官术网_书友最值得收藏!

Cleaning up SDL

Something that you may notice is missing from this code, that would be in a Windows or Linux version of an SDL application, is code that does some SDL clean up at the end of the program. If we exited an application in Windows, for instance, and did not do our cleanup work, we would be exiting without clearing out some of the memory allocated by SDL. If this were not a WebAssembly module, the following lines would be included at the end of the function:

SDL_Delay(5000);
SDL_DestroyWindow(window);
SDL_Quit();

Because we have not spent the time to make a game loop, we would want to delay the cleanup and exiting of the program by five seconds using a call to SDL_Delay(5000), 5000 being the number of milliseconds to wait before doing the cleanup. We want to reiterate that, because we are compiling to WebAssembly, we do not want to clean up our SDL. Doing so has different effects on different browsers.

When testing this code in Firefox, using the delay is unnecessary, because the web browser tab will stay open even after the WebAssembly module stops executing. However, the Chrome browser tab will display an error page as soon as SDL destroys the window object.

The SDL_DestroyWindow function would destroy the window object if this were a Windows environment. The SDL_Quit function terminates the SDL engine, and, finally, return EXIT_SUCCESS; exits successfully from the main function.

主站蜘蛛池模板: 错那县| 那曲县| 荔波县| 尼玛县| 平顺县| 龙陵县| 株洲县| 阿坝| 永寿县| 合肥市| 清新县| 丰原市| 鄯善县| 库伦旗| 吉首市| 金川县| 辉南县| 平定县| 讷河市| 淮南市| 密山市| 枣阳市| 民乐县| 韩城市| 富顺县| 米易县| 贵定县| 改则县| 穆棱市| 安陆市| 鹤壁市| 常州市| 裕民县| 绥芬河市| 乌拉特后旗| 武胜县| 兰考县| 松江区| 灵武市| 祁门县| 英超|