1

When running the following D code I get a strange SDL error:

import std.string;
import derelict.sdl2.sdl;

pragma(lib, "DerelictUtil");
pragma(lib, "DerelictSDL2");

int main(){
        DerelictSDL2.load();
        if(SDL_Init(SDL_INIT_VIDEO) < 0){
        throw new Exception(format("Error initalizing SDL: %s", SDL_GetError()));
        } 
        return 0;
}

Which returns the following from SDL_GetError()

object.Exception@min.d(12): Error initalizing SDL: 7F2802391940
----------------
./min(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x1c) [0x434284]
./min(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x2a) [0x433bfe]
./min(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3b) [0x4342cb]
./min(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x2a) [0x433bfe]
./min(main+0xd1) [0x433b89]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f28023b776d]
----------------

I am running this against the latest version of SDL2, built from mercurial. The d code is compiled with dmd v2.060. It looks like the number 7F2802391940 is garbage, but calling SDL_ClearError beforehand still produces a similar hex error message.

4

1 回答 1

2

7F2802391940可能是错误消息的地址(存储为以空字符结尾的字符串)。D 的format函数不理解这些(或者更确切地说,将它们视为任何其他指针),因此将其显式转换为 D 字符串text(SDL_GetError())(不要忘记 import std.conv)。

于 2012-08-15T19:54:00.200 回答