wails
wails copied to clipboard
[V2] Linux toggling fullscreen crashes
Description
After the tag v2.0.0-beta.39.2 toggling fullscreen causes a crash on linux.
As @leaanthony suggested in #1653 I did a git bisect and it seems that ae756a8409bce442c881e24cfe2a0430d603440f is the first bad commit.
To Reproduce
- Create a new Wails app.
- Change the greet function to toggle the fullscreen mode:
JS code:
import {WindowFullscreen, WindowUnfullscreen} from '../wailsjs/runtime/runtime'
let fs = false;
try {
if (fs) {
fs = false;
WindowUnfullscreen();
} else {
fs = true;
WindowFullscreen()
}
} catch (err) {
console.error(err);
}
- Push the button 2-3 times and see the program exit.
Expected behaviour
I expect the screen mode to be toggled.
Screenshots
No response
Attempted Fixes
I think the issue is caused by the introduction of getCurrentMonitorGeometry(window); in v2/internal/frontend/desktop/linux/window.go:65
When I restore the function to its previous version the program is not crashing anymore.
previous:
static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int max_width, int max_height) {
GdkGeometry size;
size.min_width = size.min_height = size.max_width = size.max_height = 0;
int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE;
size.max_height = (max_height == 0 ? INT_MAX : max_height);
size.max_width = (max_width == 0 ? INT_MAX : max_width);
size.min_height = min_height;
size.min_width = min_width;
gtk_window_set_geometry_hints(window, NULL, &size, flags);
}
current:
static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int max_width, int max_height) {
GdkGeometry size;
size.min_width = size.min_height = size.max_width = size.max_height = 0;
GdkRectangle monitorSize = getCurrentMonitorGeometry(window);
int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE;
size.max_height = (max_height == 0 ? monitorSize.height : max_height);
size.max_width = (max_width == 0 ? monitorSize.width : max_width);
size.min_height = min_height;
size.min_width = min_width;
gtk_window_set_geometry_hints(window, NULL, &size, flags);
}
System Details
System
------
OS: Ubuntu
Version: 22.04
ID: ubuntu
Go Version: go1.18.4
Platform: linux
Architecture: amd64
Wails
------
Version: v2.0.0-beta.42
Package Manager: apt
Dependency Package Name Status Version
---------- ------------ ------ -------
*docker docker.io Installed 20.10.17
gcc build-essential Installed 12.9ubuntu3
libgtk-3 libgtk-3-dev Installed 3.24.33-1ubuntu2
libwebkit libwebkit2gtk-4.0-dev Installed 2.36.4-0ubuntu0.22.04.1
npm npm Installed 6.14.13
*nsis nsis Available 3.08-2
pkg-config pkg-config Installed 0.29.2-1ubuntu3
Additional context
No response
I installed the same version of Ubuntu on a spare laptop yesterday so I can start looking at this properly 👍
Awesome, let me know if there's something I can help with!
FYI the issue exists on pop os 22.04 and the latest raspbian 32bit as well.
Edit: To me it seems like sometimes it can't get the monitor and its accessing a nil pointer (by the error message). And sometimes it just exists with no error, which is odd to me.
But I didn't have time to dig deeper.
Reproduced :+1: The fundamental issue is :100: related to the Scaling fix. As you mentioned, it looks like the call to get the geometry size sometimes fails....
@Lyimmi - Could you please try the linked PR? I'm not 100% sure why this appears to fix it but it certainly does on my system. I even stress tested it with toggling every 100ms from Go and it was fine. IF there are any crashes, can you please post the debug output in the console? wails build -debug 🤞
@leaanthony I tried the PR, it appears to fix the issue, both on ubuntu 22.04 and rapsbian 32bit as well!
I could not get it to crash!
PS:
Could it be that the invokeOnMainThread() uses g_idle_add() which is a thread safe function, and with the previous solution the C.SetMinMaxSize() could have been called form any goroutine, which ended in a race condition?
Yay! I'm glad it works. I'm not sure it is because most of the calls happen from other C functions that should themselves be on the main thread. I'm curious if the reordering of setsize and setminmaxsize affected things