2012-05-25 107 views
3

我試圖在OSX 10.7運行此:「段錯誤:11」利用廢棄和OpenGL

/** 
* simple.d 
*/ 

import std.stdio; 
import derelict.sdl.sdl; 
import derelict.sdl.macinit.SDLMain; 
import derelict.opengl.gl; 

pragma(lib, "/usr/local/src/Derelict2/lib/libDerelictUtil.a"); 
pragma(lib, "/usr/local/src/Derelict2/lib/libDerelictSDL.a"); 
pragma(lib, "/usr/local/src/Derelict2/lib/libDerelictGL.a"); 

int main(string[] args) { 

    // Load Derelict 
    writeln("Loading SDL..."); 
    DerelictSDL.load(); 

    // Initialise SDL 
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1) { 
     throw new Exception("SDL initialization failed"); 
    } 

    // Enable Double Buffering 
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 

    // Set up the screen 
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); 
    if (screen == null) { 
     throw new Exception("Screen is null"); 
    } 
    SDL_WM_SetCaption("Simple", "Simple"); 

    // Print OpenGL and GLSL version 
    writeln("Version Info"); 
    writeln("OpenGL:\t", glGetString(GL_VERSION)); 
    writeln("GLSL:\t", glGetString(GL_SHADING_LANGUAGE_VERSION)); 

    // Execute frame update 
    SDL_GL_SwapBuffers(); 

    // Quit SDL; SDL_Quit() takes care of freeing the screen surface 
    writeln("Quitting SDL..."); 
    SDL_Quit(); 

    writeln("Bye!"); 
    return 0; 
} 

它編譯罰款,但是當我嘗試運行它,我得到:

$ ./simple 
Loading SDL... 
Version Info 
Segmentation fault: 11 

這裏的線程輸出:

Thread 0:: Dispatch queue: com.apple.main-thread 
0 libsystem_kernel.dylib   0x00007fff8376282a __kill + 10 
1 libsystem_c.dylib    0x00007fff8e965cfa _sigtramp + 26 
2 ???        000000000000000000 0 + 0 
3 simple       0x000000010d299db9 D2rt6dmain24mainUiPPaZi7runMainMFZv + 29 
4 simple       0x000000010d29976e D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 38 
5 simple       0x000000010d299e06 D2rt6dmain24mainUiPPaZi6runAllMFZv + 58 
6 simple       0x000000010d29976e D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 38 
7 simple       0x000000010d2996f9 main + 237 
8 simple       0x000000010d24a554 start + 52 

Thread 1 Crashed:: Dispatch queue: com.apple.libdispatch-manager 
0 libsystem_kernel.dylib   0x00007fff837637e6 kevent + 10 
1 libdispatch.dylib    0x00007fff896b378a _dispatch_mgr_invoke + 923 
2 libdispatch.dylib    0x00007fff896b231a _dispatch_mgr_thread + 54 

現在,如果我嘗試編譯都在32位模式遺棄和simple.d-m32 )我得到這樣的輸出,而不是:

$ ./simple 
Loading SDL... 
Version Info 
Bus error: 10 

主題輸出:

Thread 0:: Dispatch queue: com.apple.main-thread 
0 libsystem_kernel.dylib   0x93107332 __kill + 10 
1 libsystem_kernel.dylib   0x93106932 kill$UNIX2003 + 32 
2 libsystem_c.dylib    0x943f175e raise + 26 
3 libsystem_c.dylib    0x9447d59b _sigtramp + 43 
4 ???        0xffffffff 0 + 4294967295 
5 SDL        0x01bb7108 SDL_Error + 275 
6 simple       0x000760ab D2rt6dmain24mainUiPPaZi7runMainMFZv + 23 
7 simple       0x00075a6c D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 24 
8 simple       0x000760f3 D2rt6dmain24mainUiPPaZi6runAllMFZv + 59 
9 simple       0x00075a6c D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 24 
10 simple       0x00075a0c main + 184 
11 simple       0x00035bb5 start + 53 

Thread 1 Crashed:: Dispatch queue: com.apple.libdispatch-manager 
0 libsystem_kernel.dylib   0x9310890a kevent + 10 
1 libdispatch.dylib    0x96a74e10 _dispatch_mgr_invoke + 969 
2 libdispatch.dylib    0x96a7385f _dispatch_mgr_thread + 53 

我已經試過像glClearColor()其他gl...功能和它們產生相同的結果。

回答

6

你沒有加載GL函數指針。

DerelictGL.load(); 
+0

YESS!謝謝! – bjz