I am using Manjaro linux and SDL 2. However, when I build the application in debug mode and use gdb or something like qtcreator with gdb, to debug it, it gives me a segfault, when the function SDL_Init() is called. The code I am trying this with:

#include <iostream>
#include <SDL2/SDL.h>

int main(int argc, char *argv[])
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        printf("SDL Init error: %s", SDL_GetError());
        return -1;

    SDL_Window *window = SDL_CreateWindow("window", 10, 120, 800, 640, 0);

    SDL_Renderer *ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    bool running = true;
    while (running)
        SDL_Event e;
        if (SDL_PollEvent(&e) != 0)
                case(SDL_QUIT): running = false;



    return 0;

I then recompiled SDL for debugging and went into the source, to find out this function in SDL.c is actually the cause:

        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
            if (SDL_VideoInit(NULL) < 0) {             <- this here is causing the segfault
                return (-1);

I don't know what to even do with this. None of the SDL versions work anymore. I've tried installing older ones, compiling from source.

  • \$\begingroup\$ You will have to debug your program if you don't accidentally find someone with a similar problem. Since you haven't provided details, it can be anything not necessaruly that call, something that happened earlier, a dangling/uninitialized pointer, a confused memory segment ... i'd try valgrind from the command line and leave IDEs alone for that purpose. \$\endgroup\$ – user144188 Nov 30 '20 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.