wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.29k stars 516 forks source link

MacOS : SetBitmapPressed #2001

Open bitlogik opened 3 years ago

bitlogik commented 3 years ago

Operating system: MacOS 11, x86_64 arch

wxPython version & source: 4.1.1, installed with pipy prebuilt (pip install)

Python version & source: Officials pkg from Python.org 3.6.8, 3.8.10 and 3.9.6 Probably others I just tested these.

Description of the problem: Our new version of Uniblow was generating a segmentation fault when starting on MacOS. After investigation, this seems to affect all Python versions. This change broke the start of the program. Then we identified the root cause : SetBitmapPressed(NullBitmap).

There's a segmentation fault of the Python interpreter when calling SetBitmapPressed with a null bitmap. More specifically, this is the wx 3.1.5 on Cocoa which tries to access an invalid address, probably from a past dereferenced object. A GetImage pointer seems out of his mind.

EXC_BAD_ACCESS (SIGSEGV)
KERN_INVALID_ADDRESS at 0x0000000000000000

0   libwx_osx_cocoau_core-3.1.5.0.0.dylib   0x000000010ed9fd5d wxBitmapRefData::GetImage() const + 13
1   libwx_osx_cocoau_core-3.1.5.0.0.dylib   0x000000010ee3f1be wxButtonCocoaImpl::SetPressedBitmap(wxBitmap const&) + 142
2   libwx_osx_cocoau_core-3.1.5.0.0.dylib   0x000000010edaef5a wxAnyButton::DoSetBitmap(wxBitmap const&, wxAnyButtonBase::State) + 138
3   _core.cpython-39-darwin.so      0x000000010dff0b0e meth_wxAnyButton_SetBitmapPressed(_object*, _object*, _object*) + 158

We're not sure if this issue comes from MacOS 11, or is also present in other version such as X (10.10). It was only tested on MacOS 11 (x86_64).

Here's a minimal reproduction of the problem.

from wx import (
   App,
   Frame,
   BoxSizer,
   BitmapButton,
   ID_ANY,
   NullBitmap,
   Panel,
   HORIZONTAL,
)

app = App()
frame = Frame(None, ID_ANY, "Testing")
panel = Panel(frame)
bSizer = BoxSizer(HORIZONTAL)

btn = BitmapButton(frame, ID_ANY, NullBitmap)
btn.SetBitmap(NullBitmap)
btn.SetBitmapPressed(NullBitmap) # <- Crash here : segmentation fault

bSizer.Add(btn)
frame.Show(True)
app.MainLoop()

We're working on a workaround. The easiest might be not to initialize SetBitmapPressed, and skip the faulty line.

I have the feeling this issue is more on the wxWidgets side in C++. Let us know if relevant, and where the wx support is, and we'll opened an issue on their side.

Here's the full crash report from MacOS.

swt2c commented 3 years ago

Yes, you would probably be best to open a ticket at https://trac.wxwidgets.org/.

BTW, your reproducer has some errors.

bitlogik commented 3 years ago

OK, thanks, we fixed the issue demo. We'll open an issue where your point to. I let open for now, you can close when the wxWidgets will fix and this will be integrated in wxPython, like a remainder.

bitlogik commented 3 years ago

Here the corresponding ticket on the wxWidgets side https://trac.wxwidgets.org/ticket/19257