October 22, 2024
Chicago 12, Melborne City, USA
C#

SDL_CreateRenderer freezes/hangs


I used GDB and found out that SDL_Init and SDL_CreateWindow works, but when the code comes to SDL_CreateRenderer it calls it and hangs, it never returns and GDB just waits. Also, the CPU usage for the program goes from standard 0.something to 4% (I can hear the CPU fan speeding up so it could be something like an infinite loop?) and when I type "exit" it tries to exit (through exit(0);) but to no avail. (I have another thread that takes std input and processes it.)

The SDL initialization part looks as follows:

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("Could not initiate the window for VGA module! SDL Error: %s\n", SDL_GetError());
    return;
}

window = SDL_CreateWindow("PT16B00 CPU - Emulator - VGA Module",
            SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
            SCREEN_WIDTH, SCREEN_HEIGHT, 0);
if (window == NULL) {
    printf("VGA module: Window could not be created! SDL Error: %s\n", SDL_GetError());
    return;
}

renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
    printf("VGA module: Renderer could not be created! SDL Error: %s\n", SDL_GetError());
    return;
}

screen_texture = SDL_CreateTexture(renderer,
        SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING,
        SCREEN_WIDTH, SCREEN_HEIGHT);
if (screen_texture == NULL) {
    printf("VGA module: Texture could not be created! SDL Error: %s\n", SDL_GetError());
    return;
}

I also tried using

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

and

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);

but none worked.

P.S. I have the event polling loop; the SDL_GetNumRendererDrivers() returns 3; SDL_CreateWindow() opens a window and SDL_CreateRenderer() closes it before entering the "infinite loop" (if that’s the case).



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video