Exception 0xC0000005 thrown by a basic C++ SDL program when run from Visual Studio

0

Using SDL 2.0.14 I wrote a basic main function creating an empty window and closing it upon a SDL_QUIT event. When run from the Visual Studio 2019 IDE I am using (x64 platform, both Debug and Release modes), the program works fine up to the point when the window is closed; then the IDE generates the following message:

Exception thrown at 0x00007FFBFAE55BB6 (ntdll.dll) in my_program.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFBEA2000F.

It also points to the code in the exe_common.inl file. The compiled executable runs without any visible problems though.

The single source file of my program contains the following:

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

int main(int argc, char* args[]){
    const int window_width{ 800 };
    const int window_height{ 600 };
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        std::cout << "SDL init failed" << std::endl;
        return 1;
    }
    SDL_Window* window = SDL_CreateWindow(
        "My Program",
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        window_width,
        window_height,
        SDL_WINDOW_SHOWN);

    if (!window) {
        SDL_Quit();
        std::cout << "Could not create window: " << SDL_GetError() << std::endl;
        return 2;
    }

    bool quit = false;
    SDL_Event event;
    while (!quit) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

screenshot of my Call Stack window

c++
sdl-2
asked on Stack Overflow Apr 24, 2021 by raw_stick • edited Apr 24, 2021 by genpfault

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0