I can not figure out why the dialog messages get displayed before the "printf" statement.
If I add a '\n' to the "printf" than it acts like normal, but without it the dialog boxs ends up being displayed before the "printf".
Here is the test program:
/* Build: gcc -o test `sdl2-config --libs --cflags` test.c */
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
void MessageBox(void);
void clean(void);
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
atexit(clean);
SDL_DisplayMode mode;
int id = 0;
SDL_GetCurrentDisplayMode(id, &mode);
char smode[20];
sprintf(smode, "%ix%i@%iHz", mode.h, mode.w, mode.refresh_rate);
printf("%s", smode);
MessageBox();
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Missing file",
"File is missing. Please reinstall the program.",
NULL
);
return(0);
}
void MessageBox() {
const SDL_MessageBoxButtonData buttons[] ={ /* .flags, .buttonid, .text */
{0, 0, "no"},
{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "yes" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "cancel" },
};
const SDL_MessageBoxColorScheme colorScheme = { /* .colors (.r, .g, .b) */
{ /* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */
{ 0, 0, 0 },
/* [SDL_MESSAGEBOX_COLOR_TEXT] */
{ 0, 255, 0 },
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */
{ 255, 255, 255 },
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */
{ 0, 0, 0 },
/* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */
{ 255, 0, 255 }
}
};
const SDL_MessageBoxData messageboxdata = {
SDL_MESSAGEBOX_INFORMATION, /* .flags */
NULL, /* .window */
"example message box", /* .title */
"select a button", /* .message */
SDL_arraysize(buttons), /* .numbuttons */
buttons, /* .buttons */
&colorScheme /* .colorScheme */
};
int buttonid;
if(SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) {
SDL_Log("error displaying message box");
}
if(buttonid == -1) {
SDL_Log("no selection");
} else {
SDL_Log("selection was %s", buttons[buttonid].text);
}
}
void clean() {
SDL_Quit();
}