ggarra13/mrv2

Running Python plugin menu entry with Qt window open appears to create a hard crash

Closed this issue · 3 comments

BigRoy commented

Issue

Whenever a I run a Qt window from one button and with that window still open run a Qt Window from another button then MRV2 goes down with a hard crash. Whenever I have an open Qt Windows with a running QApplication instance and I click another menu entry from the MRV2 Python Plugin menu (even if the callback to the menu entry does nothing, e.g. a function just with pass it'll then hard crash MRV2).

This is the trace I see in console:

GOT SIGNAL 11
0: RtAudio::getDefaultInputDevice - 0x140698910720048
1: seh_filter_exe - 0x140720941501632
2: RtApi::verifyStream - 0x140698914350304
3: _C_specific_handler - 0x140720813239344
4: _chkstk - 0x140720982926016
5: RtlRaiseException - 0x140720982593584
6: KiUserExceptionDispatcher - 0x140720982920896
7: PyUnicode_FromId - 0x140719762046480
8: PyImport_Import - 0x140719762835984
9: PyImport_ImportModule - 0x140719762831920
10: RtApi::getDefaultInputDevice - 0x140698908452384
11: RtAudioError::getType - 0x140698908943376
12: RtAudio::setStreamTime - 0x140698910223200
13: Fl_Text_Editor::handle_key - 0x140719637983280
14: RtAudio::setStreamTime - 0x140698910223200
15: Fl::handle_ - 0x140719637611760
16: Fl_GDI_Font_Descriptor::~Fl_GDI_Font_Descriptor - 0x140719638184208
17: CallWindowProcW - 0x140720980354144
18: DispatchMessageW - 0x140720980353088
19: QEventDispatcherWin32::processEvents - 0x140719241279984
20: qt_plugin_query_metadata - 0x140719538638400
21: QEventLoop::exec - 0x140719240965488
22: QCoreApplication::exec - 0x140719240976704
23: QCoreApplication::exec - 0x140719240976704
24: PyCFunction_GetFlags - 0x140719761784448
25: PyOS_URandomNonblock - 0x140719762601648
26: PyEval_GetFuncDesc - 0x140719762635024
27: PyEval_EvalFrameDefault - 0x140719762608736
28: PyEval_EvalFrameDefault - 0x140719762608736
29: PyRun_FileExFlags - 0x140719763099776
30: PyRun_FileExFlags - 0x140719763099776
31: PyRun_StringFlags - 0x140719763099360

I know this is quite a stretch of a question since MRV2 itself doesn't run Qt - I'm just wondering if you have any idea what might cause it and how to work around it. If I create a new Window from the first UI itself (without setting it as a parent, then it works. It's only if I run another menu entry to launch a new Qt window)

BigRoy commented

Actually - no, the issue is worse. Whenever a Qt UI is open, and thus a Qt QApplication instance is currently running then running any menu entry of the Plugin menu - even if all it does is just pass or print("test") will take it down.

Interestingly enough this does not happen when running other menu entries of MRV.

It seems there's just a conflict with Qt's event loop getting in the way with the one from MRV as soon as you run a command from a Python plug-in.

BigRoy commented

Is there any callback mechanism, like a ping from PyFLTK that I can use to maybe do the reverse where instead of running the Qt event loop I manually call QApplication.processEvents() from the FLTK cycles? Or maybe even an update event from MRV2 itself?

BigRoy commented

I have no idea why - but running a QtWidgets.QApplication within MRV2 without calling exec_() on it seems to update the UIs just fine and it makes it so that it doesn't crash - nor do I need to 'update' MRV itself.

Whilst MRV is playing it makes the Qt UI slightly slow since it seems that MRV takes precedence for updating which is exactly what I'd like. I'd like MRV to be performing as good as it can and the Qt UI is just there as a helper.

Closing this issue for now - since this seems fine for my current use case.

For sake of just sharing an example, this runs fine:

import sys
from PySide2 import QtWidgets

app = QtWidgets.QApplication.instance()
if not app:
    app = QtWidgets.QApplication(sys.argv)
    
button = QtWidgets.QPushButton("Click to show another dialog")

def on_click():
    dialog = QtWidgets.QDialog(parent=button)
    dialog.show()

button.clicked.connect(on_click)
button.show()