I'm using the SDL functions without the SDL_main be defined. Is that fine?

后端 未结 2 940
日久生厌
日久生厌 2020-12-15 13:48

that\'s my code:

Lib.h

#ifdef ExportLib
    #define Lib __declspec(dllexport)
#else
    #define Lib __declspec(dllimport)
#endif
extern void Lib Laun         


        
相关标签:
2条回答
  • 2020-12-15 14:25

    I'm using the SDL functions without the SDL_main be defined. Is that fine?

    Possibly, possibly not. Use SDL_SetMainReady() instead to be sure:

    SDL_SetMainReady: Use this function to circumvent failure of SDL_Init() when not using SDL_main() as an entry point.

    0 讨论(0)
  • 2020-12-15 14:34

    SDL_main is for SDL's automatic initialization and cleanup. It's mostly so you don't need to do it manually, though it also goes through the effort of properly setting everything up for a windowed application on the platform where it's compiled, but it's fine to #define the macro SDL_MAIN_HANDLED before #includeing SDL.h, which will prevent SDL from turning main into a macro for SDL_main Simply make sure to initialize and quit SDL properly inside your own code.

    If you want to be sure you're doing the necessary initialization right, you can just check the source code and emulate what's there.

    Edit:

    On some platforms, SDL_Init will fail if you don't use SDL_main. You can disable this failure by calling SDL_SetMainReady before SDL_Init, but be aware this will disable SDL's error handling, and if you improperly initialize SDL after calling SDL_SetMainReady you won't get the clearest of error messages.

    Quitting SDL is much more straightforward (and also needs to be done if you're not using SDL_main):

    Just call SDL_Quit when you're done with SDL. This will properly close any SDL subsystems presently active.

    0 讨论(0)
提交回复
热议问题