[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞QMenu causes the application to crash #1012

Open
atellmer opened this issue Jun 15, 2023 · 6 comments
Open

🐞QMenu causes the application to crash #1012

atellmer opened this issue Jun 15, 2023 · 6 comments

Comments

@atellmer
Copy link

Describe the bug
If you make a simple application with a QMenu, and then call a lot of window resize events, then when you further hover over the menu, the application collapses with an error:

/c/Program Files/nodejs/npm: line 44: 9202 Segmentation fault "$NODE_EXE" "$NPM_CLI_JS" "$@"

To Reproduce
Run this code then resize the window like in the video:

import { QMainWindow, QMenuBar, QMenu, QAction } from '@nodegui/nodegui';

const win = new QMainWindow();
const menuBar = new QMenuBar();
win.setMenuBar(menuBar);

const fileMenu = new QMenu();
fileMenu.setTitle('File');

const newAction = new QAction();
newAction.setText('New');

const openAction = new QAction();
openAction.setText('Open');
fileMenu.addAction(newAction);
fileMenu.addAction(openAction);

menuBar.addMenu(fileMenu);
win.show();
(global as any).win = win;
issue.mp4

Expected behavior
App should be fine

Desktop (please complete the following information):

  • OS: Windows
  • NodeGUI version: 0.61.0
  • OS Version: 10

Additional context
In fact, it’s not even about resizing, it’s just that it’s easy to catch an error on it with this minimal code for reproduction.

@wagnerscastle
Copy link

v0.59.2 does not exhibit this crash for me. 100% reproducible with v0.60 and v0.61.

@amaillo
Copy link
amaillo commented Aug 28, 2023

I updated to the master branch version right before the v0.62.0 launch from v0.59.0 today (8/28/2023) but my project started to crash after some seconds of use, I guess this was the cause.

I decided to install v0.62.0 but got an error related to /node_modules/@nodegui/nodegui/dist/index.js directory, I did a downgrade to v0.61.2 and my project started to crash randomly again.

Tried with v0.61.0, and still the crashes were there so I did a complete downgrade to v0.59.0 and then there were no crashes...

I returned to v0.62.0 to make some tests, since my project has a fixed-size window. The crash can be triggered by hovering QMenu items in the first seconds of running the program, if I wait enough I can hover and click them safely. The crash seems to happen faster when setNativeMenuBar is true.

I removed the QMenuBar from my app and there were no crashes.

Hope that this helps, not being able to update is bad.

@onfire4g05
Copy link
onfire4g05 commented Sep 12, 2023

I'm only seeing this occur on Windows (perhaps related to QMenuBar). Not sure it's helpful, but testing with WinDbg shows the following exception:

qode!v8::internal::SetupIsolateDelegate::SetupHeap

It also doesn't seem to crash while the triggered function, if you have an action assigned to the menu item (ie, showing a dialog), is running. It'll crash after it is completed. Hover events don't seem to crash and if a menu isn't selected, it doesn't crash. v0.60 did changes to menus, so that makes sense why it only shows up in that version.

@NathanaelA
Copy link
Contributor

I have to say I'm also seeing this issue in v.065 with QMenuBar/QMenu. I do NOT get a stack trace, but it randomly exits typically on the second interaction with the menu on Linux. Hitting ALT-F for the &File menu in my app then escape twice to close the menu and exit the menu navigation then do something else that causes some other part of the screen to refresh a QWidget, then tap ALT-P for the Program menu, and boom, app crashes instantly.

@NathanaelA
Copy link
Contributor

For those who might be interested -- I did find a way to make the QMenuBar/QMenu massively more stable at least in my app.

Basically in the menu's triggered event handler I add a setTimeout(buildMenu, 250); Where the buildMenu() creates a NEW QMenuBar, and all new QMenu's and then sets the newly created QMenuBar as the main window menubar. Basically replacing and discarding the prior menu any time anything is done with a menu selection. It isn't perfect, but it does make the app usable for using more than one menu item...

@FunctionPoint
Copy link
FunctionPoint commented Sep 26, 2024

I also see this bug.
My simple app has the code fragment below.
If I open and close the File menu by clicking on it (so without selecting Exit), then soon after the app will crash.
It's not quite deterministically reproducable, so looks like a C++ memory corruption, I guess.
Further investigation shows the crash can also be triggered by just moving the mouse
over the application window (and the menu) quickly a few times, without even clicking once.
If I don't call this menu code, the apps stays stable.

	menuBar(): QMenuBar
	{
		const action = new QAction();
		action.setText( "Exit" );
		action.addEventListener( "triggered", () => { this.onFileExit(); } );

		const menu = new QMenu();
		menu.setTitle( 'File' );
		menu.addAction( action );

		const menuBar = new QMenuBar();
		menuBar.addMenu( menu );
		return menuBar;
	}

PS Running NodeGui on Windows with VSCode, all current.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants