BUG: Segfault on macOS on first mouse movement in modifyDPIForBackingScaleFactorOfWindow
When creating a QApplication and reusing it to create a 3D plot using VTK in Python on macOS, I get a segfault after 1) the window shows up, 2) renders, and then 3) I move the mouse. See related issue for a video:
https://github.com/mne-tools/mne-python/issues/10659#issuecomment-1134497911
The example there is not minimal yet -- I can make it minimal if desired -- but I figured I'd check to see if it's worthwhile first.
For what it's worth, this is on Python 3.10.4 using the conda-forge build of VTK 9.1. Using lldb
I can get more info (this is on arm64/M1, but the same thing happens on Intel hardware I think):
$ lldb python
(lldb) target create "python"
Current executable set to 'python' (arm64).
(lldb) process launch -- -u /Users/larsoner/Desktop/rep.py
Process 91919 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x843e643d642455)
frame #0: 0x0000000154953088 libvtkRenderingOpenGL2-9.1.9.1.0.dylib`-[vtkCocoaGLView modifyDPIForBackingScaleFactorOfWindow:] + 164
libvtkRenderingOpenGL2-9.1.9.1.0.dylib`-[vtkCocoaGLView modifyDPIForBackingScaleFactorOfWindow:]:
-> 0x154953088 <+164>: ldr x2, [x8, #0x1f0]
0x15495308c <+168>: ldp x29, x30, [sp, #0x20]
0x154953090 <+172>: ldp x20, x19, [sp, #0x10]
0x154953094 <+176>: ldp d9, d8, [sp], #0x30
Target 0: (python) stopped.
(lldb) up
frame #1: 0x000000015495311c libvtkRenderingOpenGL2-9.1.9.1.0.dylib`-[vtkCocoaGLView viewWillMoveToWindow:] + 88
libvtkRenderingOpenGL2-9.1.9.1.0.dylib`-[vtkCocoaGLView viewWillMoveToWindow:]:
-> 0x15495311c <+88>: ldr x8, [sp, #0x18]
0x154953120 <+92>: adrp x9, 317
0x154953124 <+96>: ldr x9, [x9, #0x460]
0x154953128 <+100>: ldr x9, [x9]
...
frame #2: 0x00000001a931044c AppKit`-[NSView _setWindow:] + 296
frame #3: 0x00000001a9b7ac54 AppKit`__21-[NSView _setWindow:]_block_invoke.460 + 304
frame #4: 0x00000001a9310b94 AppKit`-[NSView _setWindow:] + 2160
frame #5: 0x00000001a9566778 AppKit`-[NSWindow dealloc] + 840
frame #6: 0x00000001a656b38c libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 200
frame #7: 0x00000001a6567d68 libobjc.A.dylib`objc_autoreleasePoolPop + 208
frame #8: 0x00000001a92f82b4 AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3908
frame #9: 0x00000001a92e99b4 AppKit`-[NSApplication run] + 596
frame #10: 0x000000013eca341c libqcocoa.dylib`___lldb_unnamed_symbol278$$libqcocoa.dylib + 1800
frame #11: 0x0000000136315f28 QtCore`QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 544
frame #12: 0x000000013630cf48 QtCore`QCoreApplication::exec() + 128
...
frame #26: 0x000000010000468c python`main + 56
frame #27: 0x00000001003ad0f4 dyld`start + 520