Reputation: 19881
I am coding against SDL2 in C#. I decided to see what would happen when I try to create a window and not call SDL_Init
. I still get a window, all the events - mouse movement, buttons, keys up/down, all of it. I color the background and close the window. All without any issues.
How is it that I am able to do this without calling SDL_Init(SDL_INIT_VIDEO)
?
This just kind of has me baffled since every tutorial I read repeats the same thing, "You must call SDL_Init(uintFlag)
to do anything." Can anyone explain what is happening?
Upvotes: 0
Views: 579
Reputation: 19881
Taking @HolyBlackCat 's suggestion that SDL2 may check for the missing initialization, I looked at the repository :
// ~line 1487:
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
// ...
SDL_Window *window;
if (!_this) {
/* Initialize the video system if needed */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return NULL;
}
}
// ...
}
As we can see, if the SDL_INIT_VIDEO
subsystem is not initialized, then this call will take care of it. In addition, the suggestion to not rely on this behavior is sound and you should take care to properly initialize the subsystems to guard against unexpected behavior in the future.
Upvotes: 2