diff --git a/devicemodel/hw/vdisplay_sdl.c b/devicemodel/hw/vdisplay_sdl.c index 09655eb7a..b8e526d2a 100644 --- a/devicemodel/hw/vdisplay_sdl.c +++ b/devicemodel/hw/vdisplay_sdl.c @@ -1151,6 +1151,7 @@ int gfx_ui_init() { SDL_SysWMinfo info; + int num_pscreen; setenv("SDL_VIDEO_X11_FORCE_EGL", "1", 1); setenv("SDL_OPENGL_ES_DRIVER", "1", 1); @@ -1162,6 +1163,14 @@ gfx_ui_init() return -1; } + num_pscreen = SDL_GetNumVideoDisplays(); + if (vdpy.pscreen_id >= num_pscreen) { + pr_err("Monitor id %d is out of avalble range [0~%d].\n", + vdpy.pscreen_id, num_pscreen); + SDL_Quit(); + return -1; + } + SDL_GetDisplayBounds(vdpy.pscreen_id, &vdpy.pscreen_rect); if (vdpy.pscreen_rect.w < VDPY_MIN_WIDTH ||