【问题标题】:Derelict3 SDL2 and OpenGL weird SIGSEGV on DerelictGL.reload()DerelictGL.reload() 上的 Derelict3 SDL2 和 OpenGL 奇怪的 SIGSEGV
【发布时间】:2014-03-11 10:00:53
【问题描述】:

尝试在 D 上设置 SDL 和 OpenGL。特别是,SDL2 和 OpenGL 3.3 核心/前向兼容。 (尽管我在示例中省略了最后两个,因为无论它们是否存在,它都会在同一点中断)。相当于 GLFW 中的以下内容可以正常工作,所以显然我在 SDL 端搞砸了,或者 SDL 做了一些破坏 Derelict 的神奇事情 - 考虑到 Derelict-gl 并没有做那么多,这似乎很难相信除了加载一些函数指针,但某处出了点问题,我不会排除 Derelict 或 SDL 中的错误,尽管它更有可能是我的代码。

我没看到,这里是:

import std.stdio;
import std.c.stdlib;
import derelict.sdl2.sdl;
import derelict.opengl3.gl;

void fatal_error_if(Cond,Args...)(Cond cond, string format, Args args) {
    if(!!cond) {
        stderr.writefln(format,args);
        exit(1);
    }
}

void main()
{ 
    //set up D bindings to SDL and OpenGL 1.1
    DerelictGL.load();
    DerelictSDL2.load();
    fatal_error_if(SDL_Init(SDL_INIT_VIDEO),"Failed to initialize sdl!");

    // we want OpenGL 3.3
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,3);

    auto window = SDL_CreateWindow(
            "An SDL2 window",
            SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED,
            800,
            600,
            SDL_WINDOW_OPENGL); // we want this window to support OpenGL
    fatal_error_if(window is null,"Failed to create SDL window!");

    auto glprof = SDL_GL_CreateContext(window); // Create the actual context and make it current
    fatal_error_if(glprof is null,"Failed to create GL context!");

    DerelictGL.reload(); //<-- BOOM SIGSEGV

    // just some stuff so we actually see something if nothing exploded
    glClearColor(1,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT);
    SDL_GL_SwapWindow(window);
    SDL_Delay(5000);
    SDL_DestroyWindow(window);
    SDL_Quit();
    writeln("If we got to this point everything went alright...");
}

就像问题标题所说,它在 DerelictGL.reload() 上中断(它应该加载类似于 GLEW 的 OpenGL 函数)。这是堆栈跟踪...

#0  0x00007ffff71a398d in __strstr_sse2_unaligned () from /usr/lib/libc.so.6
#1  0x000000000048b8d5 in derelict.opengl3.internal.findEXT() (extname=..., extstr=0x0)
    at ../../../../.dub/packages/derelict-gl3-master/source/derelict/opengl3/internal.d:74
#2  0x000000000048b8b0 in derelict.opengl3.internal.isExtSupported() (name=..., glversion=<incomplete type>)
    at ../../../../.dub/packages/derelict-gl3-master/source/derelict/opengl3/internal.d:67
#3  0x0000000000487778 in derelict.opengl3.gl.DerelictGLLoader.reload() (this=0x7ffff7ec5e80)
    at ../../../../.dub/packages/derelict-gl3-master/source/derelict/opengl3/gl.d:48
#4  0x0000000000473bba in D main () at source/app.d:36
#5  0x00000000004980c8 in rt.dmain2._d_run_main() ()
#6  0x0000000000498022 in rt.dmain2._d_run_main() ()
#7  0x0000000000498088 in rt.dmain2._d_run_main() ()
#8  0x0000000000498022 in rt.dmain2._d_run_main() ()
#9  0x0000000000497fa3 in _d_run_main ()
#10 0x00000000004809e5 in main ()

这里的错误似乎是因为 glGetString(GL_EXTENSIONS) 返回 null。为什么我不太明白。如果我删除对 DerelictGL.reload 的调用,程序的其余部分就会运行,但这意味着 OpenGL1.1 后的函数不会被加载。

将此表述为一个实际问题 - 我做错了吗?如果有,是什么?

附加

我确认创建了 OpenGL 3.3 上下文 - glGet 分别在 GL_MAJOR_VERSION 和 GL_MINOR_VERSION 上返回 3。

【问题讨论】:

    标签: opengl sdl d derelict3


    【解决方案1】:

    这似乎是 Derelict-gl3 中的错误 - 如果我在 gl.d 中更改此行

            if( maxVer >= GLVersion.GL12 && isExtSupported( GLVersion.GL12, "GL_ARB_imaging" ) ) {
    

            if( maxVer >= GLVersion.GL12 && isExtSupported( maxVer, "GL_ARB_imaging" ) ) {
    

    它工作正常。我将在 github repo 上提交一个issue,看看是否确实如此(我不太熟悉 Derelict 的工作原理,但这对我来说似乎相当明显)。

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2012-12-25
      • 1970-01-01
      相关资源
      最近更新 更多