Reputation: 525
Should I call SDL_DestroyWindow if Window Creation fails? I have the following code below:
if(this->Window == NULL)
{
std::cout << "Error: Can't create the SDL Window \n" << SDL_GetError() << "\n";
SDL_DestroyWindow(this->Window);
std::exit(EXIT_FAILURE);
}
Is it wrong?
Upvotes: 0
Views: 999
Reputation: 13269
From the SDL wiki :
If window is NULL, this function will return immediately after setting the SDL error message to "Invalid window"
You don't have to call SDL_DestroyWindow
if you don't have a window in the first place : it will not do anything (other than setting an error message).
You can think of it like free
in C or delete
in C++. If you give them NULL
or nullptr
(respectively), they do nothing.
Upvotes: 2