Crash at wxStockGDI::GetFont on Mac

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
[email protected]
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Apr 25, 2013 2:30 pm

Crash at wxStockGDI::GetFont on Mac

Post by [email protected] »

We have build WxWidget library 2.8.12 on Mac OS x 10.6.8 using xcode project in source. When we include this library in acrobat plugin, the Acrobat crash at following location.

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000bf7fff6c
Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libSystem.B.dylib 0x9055ac06 szone_malloc_should_clear + 12
1 libSystem.B.dylib 0x9055aba8 malloc_zone_malloc + 81
2 libSystem.B.dylib 0x90558c78 malloc + 50
3 libstdc++.6.dylib 0x95b79617 operator new(unsigned long) + 36
4 0x18c98542 wxStockGDI::GetFont(wxStockGDI::Item) + 360
[email protected]
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Apr 25, 2013 2:30 pm

Re: Crash at wxStockGDI::GetFont on Mac

Post by [email protected] »

I just observed that, the samples provided in wxWidgets are working fine without crash, But when I use it in my xcode project (for acrobat plugin) then it always crash. Is this helpful information for someone to help me out ?
klehocz
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Sep 24, 2009 4:01 pm

Re: Crash at wxStockGDI::GetFont on Mac

Post by klehocz »

I see this is a bit old, but I've just hit the same issue. Did you find the cause back then, or some kind of solution?
The situation here is the same, except here it's a Photoshop plugin, and I'm on wxWidgets 3.1.3 and testing on High Sierra. The exact same code works fine when compiled as a separate app.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crash at wxStockGDI::GetFont on Mac

Post by ONEEYEMAN »

Hi,
Could you post some code?
Are you able to obtain a backtrace at the time of the crash?

Thank you.
klehocz
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Sep 24, 2009 4:01 pm

Re: Crash at wxStockGDI::GetFont on Mac

Post by klehocz »

The code is literally just calling new on a class that was derived from wxFrame, even when I stripped out everything. It appears to crash in wxFrame's constructor.
g_pWxFrame=new MainFrame(NULL, g_AppName, wxPoint(0, 0), g_WindowSize);

//This is how the wxFrame constuctor is invoked - nothing special:
class MainFrame : public wxFrame
{
public:
MainFrame(wxWindow *parent, wxString title, wxPoint pos, wxSize size) : wxFrame(parent, wxID_ANY, title, pos, size)
...

I had a standalone version where this worked fine. That earlier version of my Photoshop plugin involved forking the process, and starting that standalone. This approach appears to have problems on Catalina, so I wanted to get rid of the multi-process stuff (the reason that was necessary in the first place was memory fragmentation in the 32 bit version).

In the new (crashing) single-process version I didn't have a wxApp at first, but then I added one in case that's needed to initialize wxWidgets, but that didn't make a difference. My wild guess is that Photoshop loads some dynamic library which conflicts with wxWidgets, even though I link wxWidgets statically. Looking at the loaded shared modules one thing that looks suspect is that there is a libstdc++.6.0.9.dylib, which I believe is from GCC. I compile with LLVM and the default C++ runtime there - I've tried setting it to use libstdc++, but then it doesn't compile - it's missing #include <type_traits> which it tries to include from a wxWidgets header. I'm mostly a Windows developer normally using VisualC++, so this is a bit foreign territory for me.

The stack trace looks as follows (I've shortened it, because it basically seems to go into an infinite loop in GetFont):

frame #87122: 0x000000019593cb1e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:608 [opt]
frame #87123: 0x000000019593cb3e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:611 [opt]
frame #87124: 0x00000001958ffdbd ScarabStarFilter`wxSystemSettingsNative::GetFont(index=<unavailable>) at settings.mm:0 [opt]
frame #87125: 0x000000019593cb1e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:608 [opt]
frame #87126: 0x000000019593cb3e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:611 [opt]
frame #87127: 0x00000001958ffdbd ScarabStarFilter`wxSystemSettingsNative::GetFont(index=<unavailable>) at settings.mm:0 [opt]
frame #87128: 0x000000019593cb1e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:608 [opt]
frame #87129: 0x000000019593cb3e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:611 [opt]
frame #87130: 0x00000001958ffdbd ScarabStarFilter`wxSystemSettingsNative::GetFont(index=<unavailable>) at settings.mm:0 [opt]
frame #87131: 0x000000019593cb1e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:608 [opt]
frame #87132: 0x000000019593cb3e ScarabStarFilter`wxStockGDI::GetFont(this=0x0000000195b67d98, item=<unavailable>) at gdicmn.cpp:611 [opt]
frame #87133: 0x00000001958ffdbd ScarabStarFilter`wxSystemSettingsNative::GetFont(index=<unavailable>) at settings.mm:0 [opt]
frame #87134: 0x000000019599908a ScarabStarFilter`wxWindowBase::GetClassDefaultAttributes((null)=<unavailable>) at wincmn.cpp:1600 [opt]
frame #87135: 0x00000001959bcc24 ScarabStarFilter`wxWindowBase::GetDefaultAttributes(this=<unavailable>) const at window.h:1115 [opt]
frame #87136: 0x0000000195998efb ScarabStarFilter`wxWindowBase::GetForegroundColour(this=0x000000011eab8200) const at wincmn.cpp:1634 [opt]
frame #87137: 0x000000019587e5f7 ScarabStarFilter`wxWindow::MacUpdateControlFont(this=0x000000011eab8200) at window_osx.cpp:508 [opt]
frame #87138: 0x000000019587e6ca ScarabStarFilter`wxWindow::SetFont(this=0x000000011eab8200, font=<unavailable>) at window_osx.cpp:519 [opt]
frame #87139: 0x000000019587e51a ScarabStarFilter`wxWindow::DoSetWindowVariant(this=0x000000011eab8200, variant=wxWINDOW_VARIANT_NORMAL) at window_osx.cpp:0 [opt]
frame #87140: 0x00000001958788c6 ScarabStarFilter`wxNonOwnedWindow::Create(this=0x000000011eab8200, parent=0x0000000000000000, id=<unavailable>, posOrig=0x00007ffeefbfa598, sizeOrig=<unavailable>, style=<unavailable>, name=<unavailable>) at nonownedwnd_osx.cpp:150 [opt]
frame #87141: 0x000000019587b751 ScarabStarFilter`wxTopLevelWindowMac::Create(this=0x000000011eab8200, parent=<unavailable>, id=<unavailable>, title=0x00007ffeefbfa8f8, pos=<unavailable>, size=<unavailable>, style=541101632, name=0x00007ffeefbfa5f0) at toplevel_osx.cpp:75 [opt]
frame #87142: 0x000000019569f8d2 ScarabStarFilter`wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 96
frame #87143: 0x000000019569ce3e ScarabStarFilter`MainFrame::MainFrame(wxWindow*, wxString, wxPoint, wxSize) + 114
frame #87144: 0x000000019569c16f ScarabStarFilter`ShowGUI(int, int, int, int, int) + 172
frame #87145: 0x0000000195699395 ScarabStarFilter`DoUI() + 69
frame #87146: 0x00000001956928a5 ScarabStarFilter`DoStart() + 168
frame #87147: 0x0000000195692644 ScarabStarFilter`PluginMain + 128
frame #87148: 0x0000000105cc1be2 Adobe Photoshop
Last edited by klehocz on Thu Apr 30, 2020 10:39 am, edited 1 time in total.
klehocz
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Sep 24, 2009 4:01 pm

Re: Crash at wxStockGDI::GetFont on Mac

Post by klehocz »

One theory I had is that this is due to some C++ standard library mixup - libc++ vs libstdc++. I've now tried linking to libc++ statically, also compiling wxWidgets that way, but that didn't make the issue go away (same effect as earlier). I also gave compiling wxWidgets and my plugin with libstdc++ another go - it compiles/links if I uncomment HAVE_TYPE_TRAITS in setup.h and compile the plugin with C++98, but then it gets stuck in an infinite loop elsewhere.

The debugger takes me to this line in strconv.cpp in wxWidgets:
WX_DEFINE_GLOBAL_CONV(wxCSConv, wxConvLocal, (wxFONTENCODING_SYSTEM));

Stack trace:

ScarabStarFilter`wxLog::GetComponentLevel(componentOrig=0x00007ffeefbf5c08) at log.cpp:617
frame #1: 0x00000001982e4e9a ScarabStarFilter`wxLog::IsLevelEnabled(level=7, component=0x00007ffeefbf5c08) at log.h:406
frame #2: 0x0000000198266687 ScarabStarFilter`wxCSConv::DoCreate(this=0x000000019877b8c8) const at strconv.cpp:2938
frame #3: 0x000000019826721c ScarabStarFilter`wxCSConv::wxCSConv(this=0x000000019877b8c8, encoding=wxFONTENCODING_SYSTEM) at strconv.cpp:2882
frame #4: 0x000000019826725b ScarabStarFilter`wxCSConv::wxCSConv(this=0x000000019877b8c8, encoding=wxFONTENCODING_SYSTEM) at strconv.cpp:2870
frame #5: 0x00000001982681ab ScarabStarFilter`wxGet_wxConvLocalPtr() at strconv.cpp:3300
frame #6: 0x000000019826ae19 ScarabStarFilter`::__cxx_global_var_init.16() at strconv.cpp:3300
frame #7: 0x000000019826aefc ScarabStarFilter`_GLOBAL__sub_I_strconv.cpp at strconv.cpp:0
frame #8: 0x000000010c7d4a7a dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 420
frame #9: 0x000000010c7d4caa dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
frame #10: 0x000000010c7d01cc dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 330
frame #11: 0x000000010c7cf302 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 134
frame #12: 0x000000010c7cf396 dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 74
frame #13: 0x000000010c7c33e5 dyld`dyld::runInitializers(ImageLoader*) + 82
frame #14: 0x000000010c7cc05c dyld`dlopen + 527
frame #15: 0x00007fff530f1d86 libdyld.dylib`dlopen + 86
frame #16: 0x00007fff2ae1a688 CoreFoundation`_CFBundleDlfcnLoadBundle + 152
frame #17: 0x00007fff2ae1a50f CoreFoundation`_CFBundleLoadExecutableAndReturnError + 527
frame #18: 0x00007fff2ae52d40 CoreFoundation`CFBundleGetFunctionPointerForName + 48
Post Reply