Fix window resize not always working

Change doresize to atomic_flag to prevent race condition
This commit is contained in:
ts-korhonen
2021-12-17 22:15:21 +02:00
parent 3a5c0383c2
commit 805638ddd8
6 changed files with 22 additions and 18 deletions

View File

@@ -35,6 +35,7 @@
#include <direct.h>
#include <wchar.h>
#include <io.h>
#include <stdatomic.h>
#define HAVE_STDARG_H
#include <86box/86box.h>
#include <86box/config.h>
@@ -550,12 +551,11 @@ main_thread(void *param)
// Sleep(1);
/* If needed, handle a screen resize. */
if (doresize && !video_fullscreen && !is_quit) {
if (!atomic_flag_test_and_set(&doresize) && !video_fullscreen && !is_quit) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
else
plat_resize(scrnsz_x, scrnsz_y);
doresize = 0;
}
}
@@ -1162,7 +1162,7 @@ plat_setfullscreen(int on)
video_fullscreen &= 1;
video_force_resize_set(1);
if (!(on & 1))
doresize = 1;
atomic_flag_clear(&doresize);
win_mouse_init();

View File

@@ -133,7 +133,7 @@ SpecifyDimensionsDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM
scrnsz_x = fixed_size_x;
scrnsz_y = fixed_size_y;
doresize = 1;
atomic_flag_clear(&doresize);
GetWindowRect(hwndMain, &r);

View File

@@ -672,7 +672,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
scrnsz_x = unscaled_size_x;
scrnsz_y = unscaled_size_y;
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@@ -771,7 +771,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
reset_screen_size();
device_force_redraw();
video_force_resize_set(1);
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@@ -786,7 +786,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case IDM_VID_HIDPI:
dpi_scale = !dpi_scale;
CheckMenuItem(hmenu, IDM_VID_HIDPI, dpi_scale ? MF_CHECKED : MF_UNCHECKED);
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@@ -947,7 +947,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
else
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
} else if (!user_resize)
doresize = 1;
atomic_flag_clear(&doresize);
break;
case WM_WINDOWPOSCHANGED:
@@ -992,13 +992,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (temp_x != scrnsz_x || temp_y != scrnsz_y) {
scrnsz_x = temp_x;
scrnsz_y = temp_y;
doresize = 1;
atomic_flag_clear(&doresize);
}
} else {
if (rect.right != scrnsz_x || rect.bottom != scrnsz_y) {
scrnsz_x = rect.right;
scrnsz_y = rect.bottom;
doresize = 1;
atomic_flag_clear(&doresize);
}
}
@@ -1160,7 +1160,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* If window is not resizable, then tell the main thread to
resize it, as sometimes, moves can mess up the window size. */
if (!vid_resize)
doresize = 1;
atomic_flag_clear(&doresize);
break;
}