Skip to content

Commit f32d325

Browse files
committed
fix: clamp saved window size to minimum size
The stored `vid_last` window size in Launch.cfg (or SimpleGraphic.cfg) can have a zero window width/height recorded; this typically due to closing the program while minimized. As we have a minimum window size enforced in general, adapt the config loading to clamp the size to the minimum size and safeguard against the erroneous size and position being stored in the first place.
1 parent 23a0c59 commit f32d325

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

engine/core/core_video.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ void core_video_c::Apply(bool shown)
9292
set.flags|= VID_MAXIMIZE;
9393
} else if (vid_resizable->intVal == 3) {
9494
if (sscanf(vid_last->strVal.c_str(), "%d,%d,%d,%d,%d", set.save.size + 0, set.save.size + 1, set.save.pos + 0, set.save.pos + 1, (int*)&set.save.maximised) == 5) {
95+
// Clamp saved window size as it may be persisted as zero before.
96+
set.save.size[0] = (std::max)(CFG_VID_MINWIDTH, set.save.size[0]);
97+
set.save.size[1] = (std::max)(CFG_VID_MINHEIGHT, set.save.size[1]);
9598
set.flags|= VID_USESAVED;
9699
} else {
97100
set.flags|= VID_MAXIMIZE;

engine/system/win/sys_video.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,21 @@ void sys_video_c::FramebufferSizeChanged(int width, int height) {
604604

605605
void sys_video_c::SizeChanged(int width, int height, bool max)
606606
{
607-
vid.size[0] = width;
608-
vid.size[1] = height;
609-
vid.maximised = max;
607+
// Avoid persisting an invalid window size from being minimized.
608+
if (!glfwGetWindowAttrib(wnd, GLFW_ICONIFIED)) {
609+
vid.size[0] = width;
610+
vid.size[1] = height;
611+
vid.maximised = max;
612+
}
610613
}
611614

612615
void sys_video_c::PosChanged(int x, int y)
613616
{
614-
vid.pos[0] = x;
615-
vid.pos[1] = y;
617+
// Avoid persisting an invalid window location from being minimized.
618+
if (!glfwGetWindowAttrib(wnd, GLFW_ICONIFIED)) {
619+
vid.pos[0] = x;
620+
vid.pos[1] = y;
621+
}
616622
}
617623

618624
void sys_video_c::GetMinSize(int& width, int& height)

0 commit comments

Comments
 (0)