Empty SDL3 Init Error Message

Environment: SDL3 , MINGW64 installed using msys2, also installed image and ttf, windows 11, DLL present.
IDE: Dev C++
Compiler Call: -O2 -std=c++17
Linker Call: -lSDL3
Binaries:
\bin, \mingw32\bin
Libraries:
\lib, \mingw32\lib
C include:
\include
C++ include:
\include, \include\c++

Please help me, new to SDL3

Code:

#include <SDL3/SDL.h>
#include<bits/stdc++.h>
#include <windows.h>
using namespace std;
int main() {
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“SDL could not initialize! SDL_Error: |%s|\n”, SDL_GetError());
return 1;
}

// // Create window
SDL_Window* window = SDL_CreateWindow(
“SDL3 Test”,
640, // width
480, // height
SDL_WINDOW_RESIZABLE
);

// if (window == NULL) {
// printf(“Window could not be created! SDL_Error: %s\n”, SDL_GetError());
// SDL_Quit();
// return 1;
// }
//
// // Main loop
// int quit = 0;
// SDL_Event event;
//
// while (!quit) {
// while (SDL_PollEvent(&event)) {
// if (event.type == SDL_EVENT_QUIT) {
// quit = 1;
// }
// }
// // Small delay to prevent high CPU usage
// SDL_Delay(16);
// }
//
// SDL_DestroyWindow(window);
// SDL_Quit();

return 0;

}

SDL_Init returns a bool in SDL3. True on success, false on failure.

What method did you use to install SDL3 on your system?
I’m thinking perhaps SDL3 got installed somewhere instead of Library [\lib] or Include [\include] folder.
Try tracking down the SDL library and include paths and confirm that the paths are correct.

Never mind, I think Peter87 has the answer for you, there is no error because;
0 == false, anyOtherNumber == true.
Your if statement is saying “if there are no errors, then report errors and exit”, and since there are no errors, the error message is empty.
It is best to use the boolean types true and false where applicable to avoid this type of error.

No need to compare against true and false explicitly. Just use the value directly as the condition to check if it’s true, or use ! to check if it’s false.

if (!SDL_Init(SDL_INIT_VIDEO)) {
	printf("SDL could not initialize! SDL_Error: |%s|\n", SDL_GetError());
	return 1;
}
1 Like