SDL event handling not working

别等时光非礼了梦想. 提交于 2019-12-01 21:27:07

While it requires thorough debugging to determine what exactly happens, your problem is very likely to be caused by aliasing of libc's close function and yours. close is very important call used by many libraries, including Xlib (which is called by SDL). E.g. SDL_CreateWindow calls XOpenDisplay/XCloseDisplay to test display capabilities, but XCloseDisplay calls close on its connection socket, and it will call your function instead. It's hard to say what will happen after that, but it is certainly not what was intended.

Workaround is either renaming function to something else (e.g. by giving it a prefix) or by declaring it static so its name wouldn't be exported. Note that static functions may only be used within single translation unit (i.e. if your .c file contains static function, you cannot easily use it from another .c file).

Linker doesn't report multiple definitions here because libc's close is a weak symbol (nm -D /lib/libc.so.6 | egrep ' close$' reports W).

Try moving close(); right after the end of the while (run) loop and before the // Blitting nad updating. Also, move SDL_BlitSurface(imgSurface, NULL, scrsurface, NULL); SDL_UpdateWindowSurface(window); somewhere else, as it will run after your program stops running, and all code after that will also run when run is set to 0.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!