Fix window resize not always working
Change doresize to atomic_flag to prevent race condition
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -97,7 +99,7 @@
|
|||||||
/* Stuff that used to be globally declared in plat.h but is now extern there
|
/* Stuff that used to be globally declared in plat.h but is now extern there
|
||||||
and declared here instead. */
|
and declared here instead. */
|
||||||
int dopause; /* system is paused */
|
int dopause; /* system is paused */
|
||||||
int doresize; /* screen resize requested */
|
atomic_flag doresize; /* screen resize requested */
|
||||||
volatile int is_quit; /* system exit requested */
|
volatile int is_quit; /* system exit requested */
|
||||||
uint64_t timer_freq;
|
uint64_t timer_freq;
|
||||||
char emu_version[200]; /* version ID string */
|
char emu_version[200]; /* version ID string */
|
||||||
@@ -1286,9 +1288,7 @@ set_screen_size(int x, int y)
|
|||||||
|
|
||||||
/* If the resolution has changed, let the main thread handle it. */
|
/* If the resolution has changed, let the main thread handle it. */
|
||||||
if ((owsx != scrnsz_x) || (owsy != scrnsz_y))
|
if ((owsx != scrnsz_x) || (owsy != scrnsz_y))
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
else
|
|
||||||
doresize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -63,13 +63,17 @@ extern int strnicmp(const char* s1, const char* s2, size_t n);
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
#include <atomic>
|
||||||
|
#define atomic_flag std::atomic_flag
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#include <stdatomic.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Global variables residing in the platform module. */
|
/* Global variables residing in the platform module. */
|
||||||
extern int dopause, /* system is paused */
|
extern int dopause, /* system is paused */
|
||||||
doresize, /* screen resize requested */
|
|
||||||
mouse_capture; /* mouse is captured in app */
|
mouse_capture; /* mouse is captured in app */
|
||||||
|
extern atomic_flag doresize; /* screen resize requested */
|
||||||
extern volatile int is_quit; /* system exit requested */
|
extern volatile int is_quit; /* system exit requested */
|
||||||
|
|
||||||
#ifdef MTR_ENABLED
|
#ifdef MTR_ENABLED
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
#include <86box/keyboard.h>
|
#include <86box/keyboard.h>
|
||||||
@@ -531,12 +532,11 @@ main_thread(void *param)
|
|||||||
SDL_Delay(1);
|
SDL_Delay(1);
|
||||||
|
|
||||||
/* If needed, handle a screen resize. */
|
/* 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)
|
if (vid_resize & 2)
|
||||||
plat_resize(fixed_size_x, fixed_size_y);
|
plat_resize(fixed_size_x, fixed_size_y);
|
||||||
else
|
else
|
||||||
plat_resize(scrnsz_x, scrnsz_y);
|
plat_resize(scrnsz_x, scrnsz_y);
|
||||||
doresize = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
#define HAVE_STDARG_H
|
#define HAVE_STDARG_H
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
#include <86box/config.h>
|
#include <86box/config.h>
|
||||||
@@ -550,12 +551,11 @@ main_thread(void *param)
|
|||||||
// Sleep(1);
|
// Sleep(1);
|
||||||
|
|
||||||
/* If needed, handle a screen resize. */
|
/* 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)
|
if (vid_resize & 2)
|
||||||
plat_resize(fixed_size_x, fixed_size_y);
|
plat_resize(fixed_size_x, fixed_size_y);
|
||||||
else
|
else
|
||||||
plat_resize(scrnsz_x, scrnsz_y);
|
plat_resize(scrnsz_x, scrnsz_y);
|
||||||
doresize = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1162,7 +1162,7 @@ plat_setfullscreen(int on)
|
|||||||
video_fullscreen &= 1;
|
video_fullscreen &= 1;
|
||||||
video_force_resize_set(1);
|
video_force_resize_set(1);
|
||||||
if (!(on & 1))
|
if (!(on & 1))
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
|
|
||||||
win_mouse_init();
|
win_mouse_init();
|
||||||
|
|
||||||
|
@@ -133,7 +133,7 @@ SpecifyDimensionsDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM
|
|||||||
|
|
||||||
scrnsz_x = fixed_size_x;
|
scrnsz_x = fixed_size_x;
|
||||||
scrnsz_y = fixed_size_y;
|
scrnsz_y = fixed_size_y;
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
|
|
||||||
GetWindowRect(hwndMain, &r);
|
GetWindowRect(hwndMain, &r);
|
||||||
|
|
||||||
|
@@ -672,7 +672,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
scrnsz_x = unscaled_size_x;
|
scrnsz_x = unscaled_size_x;
|
||||||
scrnsz_y = unscaled_size_y;
|
scrnsz_y = unscaled_size_y;
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
config_save();
|
config_save();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -771,7 +771,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
reset_screen_size();
|
reset_screen_size();
|
||||||
device_force_redraw();
|
device_force_redraw();
|
||||||
video_force_resize_set(1);
|
video_force_resize_set(1);
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
config_save();
|
config_save();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -786,7 +786,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case IDM_VID_HIDPI:
|
case IDM_VID_HIDPI:
|
||||||
dpi_scale = !dpi_scale;
|
dpi_scale = !dpi_scale;
|
||||||
CheckMenuItem(hmenu, IDM_VID_HIDPI, dpi_scale ? MF_CHECKED : MF_UNCHECKED);
|
CheckMenuItem(hmenu, IDM_VID_HIDPI, dpi_scale ? MF_CHECKED : MF_UNCHECKED);
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
config_save();
|
config_save();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -947,7 +947,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
else
|
else
|
||||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
|
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
|
||||||
} else if (!user_resize)
|
} else if (!user_resize)
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_WINDOWPOSCHANGED:
|
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) {
|
if (temp_x != scrnsz_x || temp_y != scrnsz_y) {
|
||||||
scrnsz_x = temp_x;
|
scrnsz_x = temp_x;
|
||||||
scrnsz_y = temp_y;
|
scrnsz_y = temp_y;
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rect.right != scrnsz_x || rect.bottom != scrnsz_y) {
|
if (rect.right != scrnsz_x || rect.bottom != scrnsz_y) {
|
||||||
scrnsz_x = rect.right;
|
scrnsz_x = rect.right;
|
||||||
scrnsz_y = rect.bottom;
|
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
|
/* If window is not resizable, then tell the main thread to
|
||||||
resize it, as sometimes, moves can mess up the window size. */
|
resize it, as sometimes, moves can mess up the window size. */
|
||||||
if (!vid_resize)
|
if (!vid_resize)
|
||||||
doresize = 1;
|
atomic_flag_clear(&doresize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user