我正在尝试在 OSX 10.7 上运行它:
/**
* 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
现在,如果我尝试同时编译 Derelict 和simple.d
32 位模式(-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
我尝试过其他gl...
类似的功能glClearColor()
,它们产生了相同的结果。