[wxOSX] Crash in wxBitmap RefData::UseAlpha(book) (Issue #26763)

13 views
Skip to first unread message

alilie

unread,
Jul 31, 2026, 8:16:41 AM (4 days ago) Jul 31
to wx-...@googlegroups.com, Subscribed
alilie created an issue (wxWidgets/wxWidgets#26763)

Description

The crash occurs when loading a wxToolBar that contains a toggable tool without an attached bitmap.

Minimal example of reproducing the problem.

main.cpp
#include <wx/wx.h>
#include <wx/xrc/xmlres.h>
#include <wx/xrc/xh_toolb.h>

class MyFrame : public wxFrame
{
public:
    MyFrame()
        : wxFrame(nullptr, wxID_ANY, "Toolbar XRC Example",
                  wxDefaultPosition, wxSize(500,300))
    {
        wxImage::AddHandler(new wxPNGHandler);

        wxXmlResource::Get()->InitAllHandlers();

        wxXmlResource::Get()->Load("toolbar.xrc");

        wxToolBar* tb = (wxToolBar*)wxXmlResource::Get()->LoadObject(this, "main_toolbar", "wxToolBar");

#if 0
        wxBitmap bmp("save.png", wxBITMAP_TYPE_PNG);
        tb->SetToolNormalBitmap(XRCID("ID_TOGGLE_NAME"), bmp);
#endif

        SetToolBar(tb);
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        auto* frame = new MyFrame;
        frame->Show();
        return true;
    }
};

wxIMPLEMENT_APP(MyApp);
toolbar.xrc
<?xml version="1.0" encoding="UTF-8"?>

<resource xmlns="http://www.wxwidgets.org/wxxrc">

    <object class="wxToolBar" name="main_toolbar">
        <bitmapsize>16,16</bitmapsize>
        <object class="tool" name="ID_TOGGLE_NAME">
            <label>Toggle</label>
            <toggle>1</toggle>
        </object>
    </object>

</resource>
bt
(lldb) bt                   
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)                                          
  * frame #0: 0x00000001016d6890 libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxBitmapRefData::UseAlpha(this=0x0000000000000000, use=true) at bitmap.cpp:385:5
    frame #1: 0x00000001016da1a0 libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxBitmap::UseAlpha(this=0x00000007aee683d8, use=true) at bitmap.cpp:2076:22
    frame #2: 0x000000010180303c libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBarTool::UpdateImages(this=0x00000007aee68300) at toolbar.mm:593:27
    frame #3: 0x0000000101806d84 libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBar::DoInsertTool(this=0x00000007af1d0e00, (null)=0, toolBase=0x00000007aee68300) at toolbar.mm:1523:27
    frame #4: 0x00000001019d010c libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBarBase::InsertTool(this=0x00000007af1d0e00, pos=0, tool=0x00000007aee68300) at tbarbase.cpp:198:20            
    frame #5: 0x00000001019cff94 libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBarBase::DoInsertNewTool(this=0x00000007af1d0e00, pos=0, tool=0x00000007aee68300) at tbarbase.h:625:15
    frame #6: 0x00000001019cff4c libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBarBase::InsertTool(this=0x00000007af1d0e00, pos=0, toolid=-2008, label=0x000000016fdfc1d0, bitmap=0x000000016f
dfc1a0, bmpDisabled=0x000000016fdfc140, kind=wxITEM_CHECK, shortHelp=0x000000016fdfc0c0, longHelp=0x000000016fdfc070, clientData=0x0000000000000000) at tbarbase.cpp:183:12
    frame #7: 0x00000001019cfe0c libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxToolBarBase::DoAddTool(this=0x00000007af1d0e00, toolid=-2008, label=0x000000016fdfc1d0, bitmap=0x000000016fdfc1a0, 
bmpDisabled=0x000000016fdfc140, kind=wxITEM_CHECK, shortHelp=0x000000016fdfc0c0, longHelp=0x000000016fdfc070, clientData=0x0000000000000000, (null)=-1, (null)=-1) at tbarbase.cpp:166:12
    frame #8: 0x00000001003b1aa0 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxToolBarBase::AddTool(this=0x00000007af1d0e00, toolid=-2008, label=0x000000016fdfc1d0, bitmap=0x000000016fdfc1a0, bmp
Disabled=0x000000016fdfc140, kind=wxITEM_CHECK, shortHelp=0x000000016fdfc0c0, longHelp=0x000000016fdfc070, clientData=0x0000000000000000) at tbarbase.h:305:16
    frame #9: 0x00000001003b0bd4 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxToolBarXmlHandler::DoCreateResource(this=0x00000007af00b300) at xh_toolb.cpp:125:24
    frame #10: 0x00000001003c5d9c libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandlerImpl::CreateResource(this=0x00000007aefc65e0, node=0x00000007aec09720, parent=0x00000007af1d0e00,
 instance=0x0000000000000000) at xmlres.cpp:1518:40
    frame #11: 0x00000001003c2a40 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandler::CreateResource(this=0x00000007af00b300, node=0x00000007aec09720, parent=0x00000007af1d0e00, ins
tance=0x0000000000000000) at xmlreshandler.h:194:27
    frame #12: 0x00000001003bfb64 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResource::DoCreateResFromNode(this=0x00000007af29cd20, node=0x00000007aec09720, parent=0x00000007af1d0e00, insta
nce=0x0000000000000000, handlerToUse=0x0000000000000000) at xmlres.cpp:1123:33
    frame #13: 0x00000001003bea6c libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResource::CreateResFromNode(this=0x00000007af29cd20, node=0x00000007aec09720, parent=0x00000007af1d0e00, instanc
e=0x0000000000000000, handlerToUse=0x0000000000000000) at xmlres.h:377:23
    frame #14: 0x00000001003c57a0 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandlerImpl::CreateResFromNode(this=0x00000007aefc65e0, node=0x00000007aec09720, parent=0x00000007af1d0e
00, instance=0x0000000000000000) at xmlres.cpp:1465:35
    frame #15: 0x000000010036094c libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandler::CreateResFromNode(this=0x00000007af00b300, node=0x00000007aec09720, parent=0x00000007af1d0e00, 
instance=0x0000000000000000) at xmlreshandler.h:441:27
    frame #16: 0x00000001003b1660 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxToolBarXmlHandler::DoCreateResource(this=0x00000007af00b300) at xh_toolb.cpp:229:37
    frame #17: 0x00000001003c5d9c libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandlerImpl::CreateResource(this=0x00000007aefc65e0, node=0x00000007aec09540, parent=0x00000007af1e4000,
 instance=0x0000000000000000) at xmlres.cpp:1518:40
    frame #18: 0x00000001003c2a40 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResourceHandler::CreateResource(this=0x00000007af00b300, node=0x00000007aec09540, parent=0x00000007af1e4000, ins
tance=0x0000000000000000) at xmlreshandler.h:194:27
    frame #19: 0x00000001003bfb64 libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResource::DoCreateResFromNode(this=0x00000007af29cd20, node=0x00000007aec09540, parent=0x00000007af1e4000, insta
nce=0x0000000000000000, handlerToUse=0x0000000000000000) at xmlres.cpp:1123:33
    frame #20: 0x00000001003bf60c libwx_osx_cocoau_xrc-3.3.4.0.0.dylib`wxXmlResource::DoLoadObject(this=0x00000007af29cd20, parent=0x00000007af1e4000, name=0x000000016fdfdee8, classname=0x
000000016fdfdec0, recursive=false) at xmlres.cpp:603:19
    frame #21: 0x0000000100001560 toolbar_example`wxXmlResource::LoadObject(this=0x00000007af29cd20, parent=0x00000007af1e4000, name=0x000000016fdfdee8, classname=0x000000016fdfdec0) at xm
lres.h:207:16
    frame #22: 0x00000001000011d8 toolbar_example`MyFrame::MyFrame(this=0x00000007af1e4000) at main.cpp:18:59
    frame #23: 0x0000000100001060 toolbar_example`MyFrame::MyFrame(this=0x00000007af1e4000) at main.cpp:11:5
    frame #24: 0x0000000100000e58 toolbar_example`MyApp::OnInit(this=0x000000010128ea10) at main.cpp:34:27
    frame #25: 0x00000001016a8a58 libwx_osx_cocoau_core-3.3.4.0.0.dylib`wxApp::CallOnInit(this=0x000000010128ea10) at utils.mm:454:22
    frame #26: 0x0000000100e202b4 libwx_baseu-3.3.4.0.0.dylib`wxEntry(int&, wchar_t**)::$_0::operator()(this=0x000000016fdfe1ef) const at init.cpp:553:25
frame #27: 0x0000000100e1e9e8 libwx_baseu-3.3.4.0.0.dylib`int wxSafeCall<int, wxEntry(int&, wchar_t**)::$_0, wxEntry(int&, wchar_t**)::$_1>(func=0x000000016fdfe1ef, handler=0x000000016
fdfe1ee) at safecall.h:40:16
    frame #28: 0x0000000100e1e820 libwx_baseu-3.3.4.0.0.dylib`wxEntry(argc=0x0000000100fad638, argv=0x000000010128da80) at init.cpp:550:12
    frame #29: 0x0000000100e1ead4 libwx_baseu-3.3.4.0.0.dylib`wxEntry(argc=0x000000016fdfe288, argv=0x000000016fdfe918) at init.cpp:577:12
    frame #30: 0x0000000100000bf8 toolbar_example`main(argc=1, argv=0x000000016fdfe918) at main.cpp:40:1
    frame #31: 0x000000018bfabda4 dyld`start + 6992

The crash does not reproduce if we add <bitmap>save.png</bitmap> to the xrc file or if toggle is 0.
I tried to look for the regression with git bisect.
I had to git bisect skip on a few commits because I had compilation errors.

3.1.6 - can reproduce

The first bad commit could be any of:

15e35a5e7c9a12ebffb6fe3c66f3e55ab5a3f181
043461077ec45bb8284deda450f1f5c9cdd2be65
24df75a27f1263386908a660673f99c9dbcea9d0
9a578b9c8f50972a1d46755b63878a004a2e6311
ba6c691c221efd9ddac6837c425675d3a86ea892
7337bf1da124e58b99252cfc50e6b291a48fd5b2
95aa8e40fd66ebeb14a63e916d3dc2058b46ed69
b33df7360a4ea92d388fb7950b41c4495dcd0c08
edc95443a3a0cf2f6c045e87bf7295f84b644627
388d322b68dcd28e9084515c4917ec67e783e096
97f6c85d9bb9d11c4d635f0422b1fc8d6cb11509

3.1.5 - can't reproduce

They all have to do with the wxBitmapBundle integration.
After applying all these commits I had a similar crash.
To get the one in UseAlpha I also had to apply 2910327ef318f655171bb8c0b0db3a0529a9da0a.

The same crash can be reproduced just by running the toolbar sample. But not toolbar.app, the executable without the extension.

Platform and version information

  • wxWidgets version you use: master [3.3.4]
  • wxWidgets port you use: wxOSX
  • OS and its version: macOS Tahoe 26.4
    • GTK version:
    • Which GDK backend is used:
    • Desktop environment :
    • Current theme:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26763@github.com>

Stefan Csomor

unread,
Aug 1, 2026, 6:28:26 AM (3 days ago) Aug 1
to wx-...@googlegroups.com, Subscribed
csomor left a comment (wxWidgets/wxWidgets#26763)

@alilie thanks a lot, I'll add this to our repo as well


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26763/5151024147@github.com>

VZ

unread,
Aug 1, 2026, 8:05:37 AM (3 days ago) Aug 1
to wx-...@googlegroups.com, Subscribed

Closed #26763 as completed via 060564a.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/26763/issue_event/28817551690@github.com>

Reply all
Reply to author
Forward
0 new messages