You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
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.
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...
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.
Well I finally spent some time today figuring out the source of this issue, got tired of my app crashing so frequently from menu usage. Also found out ContextMenus can cause it to crash during my testing, but not as frequently as QMenuBar w/ a QMenu.. I bisected the changes between .58 and .60 to figure out the differences and basically manually reverted different things to test -- I'm on the latest version, but with JUST these 6 functions for the signals commented out in only the hpp files...
I'm not sure WHY this code causes it to crash, which is why I haven't submitted a PR. But I can tell you by commenting it out and rebuilding I haven't seen a single crash in my app from the menu usage yet, I've tried to crash it for a while, stuff that would crash in seconds is not causing any crashes now.
I commented out these two sets of changes (6 functions):
I realize in the second one the "trigger" existed in prior versions and isn't probably an issue, but in my code base I have all 6 functions commented out. It seems to be totally stable now.
@sedwards2009 - Do you have any ideas or thoughts why these EVENT's would be causing it to crash?
Now that I have it stable, I plan to try enabling each one to see which ones actually cause the crash, but curious to see if you can see anything specifically wrong in the code that might be responsible...
It being called so many times when you hover over it, that it must exceed the node callback stack at times causing node to fill the event buffer . The hovered event on on the QMenu gets called massive numbers of times per item as you move your mouse, I can image the QMenuBar is also called just as many times, maybe more... .
An conflict with event timings, QMenuBar -> Hovering spam, then a QMenuBar -> triggered, then a QMenu -> AboutToShow along with QMenu- -> Hovered spam,all four of these events all at basically the same time, maybe cause some sort of JS interface crash do to the number of callbacks...
Is there any code anywhere to dedup events, that might fix it if we dedup the hovered on both the QMenuItem and QMenu, but otherwise with everything else uncommented EXCEPT for this QMenuItem->Hovered signal, my app still seems stable.
Activity
wagnerscastle commentedon Jul 5, 2023
v0.59.2 does not exhibit this crash for me. 100% reproducible with v0.60 and v0.61.
amaillo commentedon 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 commentedon 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:
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 commentedon Mar 2, 2024
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 commentedon Mar 3, 2024
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
triggeredevent handler I add asetTimeout(buildMenu, 250);Where thebuildMenu()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 commentedon 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.
PS Running NodeGui on Windows with VSCode, all current.
NathanaelA commentedon Feb 5, 2025
Well I finally spent some time today figuring out the source of this issue, got tired of my app crashing so frequently from menu usage. Also found out ContextMenus can cause it to crash during my testing, but not as frequently as QMenuBar w/ a QMenu.. I bisected the changes between .58 and .60 to figure out the differences and basically manually reverted different things to test -- I'm on the latest version, but with JUST these 6 functions for the signals commented out in only the hpp files...
I'm not sure WHY this code causes it to crash, which is why I haven't submitted a PR. But I can tell you by commenting it out and rebuilding I haven't seen a single crash in my app from the menu usage yet, I've tried to crash it for a while, stuff that would crash in seconds is not causing any crashes now.
I commented out these two sets of changes (6 functions):
nodegui/src/cpp/include/nodegui/QtWidgets/QMenuBar/nmenubar.hpp
Lines 17 to 29 in 61d210b
nodegui/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp
Lines 17 to 41 in 61d210b
I realize in the second one the "trigger" existed in prior versions and isn't probably an issue, but in my code base I have all 6 functions commented out. It seems to be totally stable now.
@sedwards2009 - Do you have any ideas or thoughts why these EVENT's would be causing it to crash?
Now that I have it stable, I plan to try enabling each one to see which ones actually cause the crash, but curious to see if you can see anything specifically wrong in the code that might be responsible...
NathanaelA commentedon Feb 5, 2025
Ok after more testing and re-enabling/disabling stuff, the primary cause for the crash is this:
nodegui/src/cpp/include/nodegui/QtWidgets/QMenuBar/nmenubar.hpp
Lines 17 to 22 in 61d210b
I suspect it is a combination of:
hoveredevent on on the QMenu gets called massive numbers of times per item as you move your mouse, I can image the QMenuBar is also called just as many times, maybe more... .QMenuBar -> Hoveringspam, then aQMenuBar -> triggered, then aQMenu -> AboutToShowalong withQMenu- -> Hoveredspam,all four of these events all at basically the same time, maybe cause some sort of JS interface crash do to the number of callbacks...Is there any code anywhere to dedup events, that might fix it if we dedup the
hoveredon both the QMenuItem and QMenu, but otherwise with everything else uncommented EXCEPT for this QMenuItem->Hovered signal, my app still seems stable.NathanaelA commentedon Feb 5, 2025
Ok, well it had nothing to do with my guesses above 😀 But, I did track it down and I uploaded a PR without removing any events. #1063