SDL2 | ' SDL_ConvertSurface()'仅在Linux

时间:2015-08-17 18:48:14

标签: c++ linux c++11 cmake sdl-2

这是一个奇怪的问题。我的代码适用于Windows和Arch Linux。但是当涉及Ubuntu时,会出现问题。考虑到代码适用于另一个Linux系统和Windows,我认为问题可能与库/依赖关系有关。发生了什么是我的代码运行了一点,然后崩溃。原始代码如下所示:

SDL_Surface* bg = SDL_ConvertSurface(
        IMG_Load("Resources/Engine/launcher.jpg"),
        SDL_GetWindowSurface(GameWindow->SDLWindow)->format,
        0
        );

为了调试这段代码,我把这段代码转换成了这个烂摊子:

SDL_Surface* src = IMG_Load("Resources/Engine/launcher.jpg");
    if (!src) { log->error("background didnt load"); SDL_GetError();}
    else log->info("good to go (src)");
    SDL_Surface* fmt = SDL_GetWindowSurface(GameWindow->SDLWindow);
    if (!src) { log->error("window surface didnt load"); SDL_GetError(); }
    else log->info("good to go (fmt)");
    SDL_Surface* bg = SDL_ConvertSurface(src, fmt->format, 0);
    //^^^^^^^^^^^^^^^ This line Crashes ^^^^^^^^^^^^^^^^^^^//
    if (!bg) { log->error("surface wasnt made"); SDL_GetError(); }
    else log->info("good to go (all)");

此标记符合SDL2 API for SDL_ConvertSurface()

此函数的调试版本的输出是:

...
[2015-08-17 14:37:15.919] [Somnia] [info] good to go (src)
[2015-08-17 14:37:15.919] [Somnia] [info] good to go (fmt)
Signal: SIGSEGV (Segmentation fault)

既然我提到代码可能因为缺少库或其他东西而表现不同,我会向你们展示我链接库的CMakeList.txt。请记住,这适用于我的笔记本电脑(Arch Linux)和我的桌面(Windows 10),但不适用于我的桌面(Ubuntu)。

...
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
pkg_search_module(SDL2NET REQUIRED SDL2_net>=2.0.0)
pkg_search_module(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0)
pkg_search_module(SDL2TTF REQUIRED SDL2_ttf>=2.0.0)
...
target_link_libraries(Somnia
    ${SDL2_LIBRARIES}
    ${SDL2IMAGE_LIBRARIES}
    ${SDL2NET_LIBRARIES}
    ${SDL2MIXER_LIBRARIES}
    ${SDL2TTF_LIBRARIES}
    ${STEAMWORKS_LIBRARY}
)
...

0 个答案:

没有答案