Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When main monitor is powered off / powered on, then Assertion failure in WIN_AddDisplay #9105

Open
remss opened this issue Feb 21, 2024 · 0 comments
Assignees
Milestone

Comments

@remss
Copy link

remss commented Feb 21, 2024

I have a setup with 2 monitors. Here the repro steps:

  • I open my application and place the SDL Window on the screen 1 (the main screen).
  • When I power-off the main screen 1 then the window moves to the screen 2.
  • When I power-on the screen 1 then the window returns to the screen 1 but an assert is hit because index is 2 and display_index is 0:
Assertion failure at WIN_AddDisplay (sdl2-src\src\video\windows\SDL_windowsmodes.c:380), triggered 1 time:
  'index == *display_index'

Note that in Release there is no crash at all, just this assert hit in Debug mode.

Here a simple main.cpp to reproduce:

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

int main(int, char **)
{
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Window *window =
        SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
    if (window == nullptr)
    {
        std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (renderer == nullptr)
    {
        std::cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }

    bool quit = false;
    SDL_Event e;
    while (!quit)
    {
        while (SDL_PollEvent(&e) != 0)
        {
            if (e.type == SDL_QUIT)
            {
                quit = true;
            }
        }
        SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

  • SDL version 2.30.0 revision 859844e
  • Windows 11 version 23H2
@slouken slouken self-assigned this Feb 25, 2024
@slouken slouken added this to the 2.32.0 milestone Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants