在DerelictGL.reload()上废弃3 SDL2和OpenGL奇怪的SIGSEGV

时间:2014-02-12 20:20:19

标签: opengl sdl d derelict3

尝试在D上设置SDL和OpenGL。具体来说,SDL2和OpenGL 3.3核心/前向兼容。 (虽然我在示例中留下了最后两个,因为无论它们是否存在,它都会在同一点上断开)。相当于GLFW中的以下内容工作正常,所以显然我在SDL端搞砸了一些东西,或者SDL做了一些破坏废弃的神奇事物 - 考虑到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。

1 个答案:

答案 0 :(得分:2)

这似乎是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的工作原理并不熟悉,但这对我来说显而易见)。