Use StaticBitmap with .icns file: SetIcon segfaults

Hello,

I am trying to use display a .icns inside my GUI, but am having problems getting my code to run.
Is there any way to do this without converting to png first?

This is my example code (run on MacOS):

Python 3.12.3 on darwin, wxPython 4.2.1 osx-cocoa (phoenix) wxWidgets 3.2.2.1

import wx

import faulthandler
faulthandler.enable()

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        self.SetSize((400, 200))
        self.SetTitle("Icon Test")
        self.panel = wx.Panel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)

        sbm = wx.StaticBitmap()
        icon = wx.Icon()
        icns_path = "/System/Applications/Mail.app/Contents/Resources/ApplicationIcon.icns"
        icon.LoadFile(icns_path, type=wx.BITMAP_TYPE_ICON)
        # icon.LoadFile(icns_path, type=wx.BITMAP_TYPE_ICO)
        sbm.SetIcon(icon)  # segfaults here
        sizer.Add(sbm, 0)

        self.panel.SetSizer(sizer)
        self.Layout()


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

Output:

Fatal Python error: Segmentation fault

Current thread 0x00000002010ae600 (most recent call first):
  File "/private/tmp/test.py", line 20 in __init__
  File "/private/tmp/test.py", line 29 in <module>

Extension modules: wx._core (total: 1)
zsh: segmentation fault  python3 test.py

Attached .icns file for non-Mac users:
ApplicationIcon.icns.zip (68.7 KB)

You are not passing a parent control to the StaticBitmap.

Instead of:

    sbm = wx.StaticBitmap()

try:

    sbm = wx.StaticBitmap(self.panel)

Tested using Python 3.11.9 and wx.Python 4.2.1 osx-cocoa (phoenix) wxWidgets 3.2.2.1 on Sonoma 14.5

Thank you so much - such a silly mistake from me!