- Hands-On Game Development with WebAssembly
- Rick Battagline
- 240字
- 2021-06-24 13:41:07
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.
- Learning SQL Server Reporting Services 2012
- ATmega16單片機(jī)項(xiàng)目驅(qū)動(dòng)教程
- Creating Dynamic UI with Android Fragments
- 計(jì)算機(jī)組裝·維護(hù)與故障排除
- Unity 5.x Game Development Blueprints
- 平衡掌控者:游戲數(shù)值經(jīng)濟(jì)設(shè)計(jì)
- Mastering Manga Studio 5
- 電腦維護(hù)365問(wèn)
- 分布式微服務(wù)架構(gòu):原理與實(shí)戰(zhàn)
- 計(jì)算機(jī)組裝與維護(hù)(第3版)
- 筆記本電腦維修300問(wèn)
- Intel FPGA權(quán)威設(shè)計(jì)指南:基于Quartus Prime Pro 19集成開(kāi)發(fā)環(huán)境
- Mastering Machine Learning on AWS
- Mastering Quantum Computing with IBM QX
- Drupal Rules How-to