1
votes

The gist of the problem is that I've got a main function that initializes SDL, sets up OpenGL attributes (for the context creation) gets a context up (a class that represents an OpenGL rendering context (with window and context together)), reports some info on the OpenGL version and other basic info, and enters the usual loop that exits on the user closing the window or pressing ESC.

Except I can't test any of that because main is never entered, it appears that SDL_main.h includes a #define that replaces main with SDL_main, and the actual main is called from a static library. For some reason, that exits with a return value of 0 without ever entering the "actual" main. The weird part is that I changed nothing about the project setup from when it was minimally working (just putting some OpenGL data in a file) to now, besides adding the RenderingContext class. Removing that class from the project does not solve the problem, and I'm only linking the minimal amount of libraries to actually complete linkage.

Is there any solution to the problem, or some issue I didn't know about with SDL2 that might be affected by my project setup?

The code can be found here, most of it under the src directory, with main.cpp in the top level.

2
Maybe this will help? wiki.libsdl.org/SDL_SetMainReadyjplatte
I have no idea why, but that fixed it. I'm only confused because it was working just fine before.Cave Dweller
Okay, I'll create an answer for it, so this question can be marked solved.jplatte

2 Answers

5
votes

You have to #define SDL_MAIN_HANDLED before #include <SDL2/SDL.h>. This prevents SDL from redefining your main as SDL_main. Then, as first statement in your main, call

SDL_SetMainReady();

Source: https://wiki.libsdl.org/SDL_SetMainReady

0
votes

I had the exact same issue. Make sure you aren't using the incomplete main version:

int main(){
}

Use this instead:

int main( int arc, char* argv[] ){
}