wxMac 2.8.10 global operator new/delete problem

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
rex666
Earned a small fee
Earned a small fee
Posts: 20
Joined: Mon Nov 08, 2004 12:15 am

wxMac 2.8.10 global operator new/delete problem

Post by rex666 » Wed May 19, 2010 7:10 am

wxMac 2.8.10 on XCode 3.1.3 on OS-X 10.5.8 (problem has happened on 10.6, too) on an Intel Mac (not tested on PPC)

My project uses wxWidgets as a monolithic shared library. Another shared library in the project provides a global allocator new/delete. If I modify the allocation size to allow library data overhead with every allocation, wxWidgets eventually fails with some kind of memory error.

In every case, it seems that somehow the system is calling my operator delete from the _CFRelease related to something about changing the menu. It seems that the system is passing me a handle to some old menu data that was not allocated by my global operator new, but gets sent to my global operator delete, which causes problems.

Here's a sample stack trace, though the specific call from my code that triggers the problem can depend on what I do exactly during my startup code:

Code: Select all

#0	0x919844a9 in malloc_error_break
#1	0x9197f497 in szone_error
#2	0x918a9503 in szone_free
#3	0x918a936d in free
// --- Calls free, and ends up in error
#4	0x01813688 in _DoFree at Memory.cpp:429
#5	0x01813728 in operator delete at Memory.cpp:485
// --- My operator delete
#6	0x970af768 in HIObject::HandleClassHIObjectEvent
#7	0x970af5d3 in HIObject::EventHook
#8	0x970af13d in DispatchEventToHandlers
#9	0x970ae57b in SendEventToEventTargetInternal
#10	0x970ae3e0 in SendEventToEventTargetWithOptions
#11	0x970ede22 in HIObject::Destruct
#12	0x94a0f516 in _CFRelease
#13	0x972007e2 in MenuData::~MenuData
#14	0x970af768 in HIObject::HandleClassHIObjectEvent
#15	0x970af5d3 in HIObject::EventHook
#16	0x970af13d in DispatchEventToHandlers
#17	0x970ae57b in SendEventToEventTargetInternal
#18	0x970ae3e0 in SendEventToEventTargetWithOptions
#19	0x970ede22 in HIObject::Destruct
#20	0x94a0f516 in _CFRelease
#21	0x9712ddfa in ReleaseMenu
#22	0x9712cf5e in SystemAppMenuHandler
#23	0x970af13d in DispatchEventToHandlers
#24	0x970ae57b in SendEventToEventTargetInternal
#25	0x970ae3e0 in SendEventToEventTargetWithOptions
#26	0x970fb853 in PopulateMenu
#27	0x970fb492 in FindItemByCommand
#28	0x970fb68b in FindItemByCommand
#29	0x970fb344 in _GetIndMenuItemWithCommandID
#30	0x9719177f in DisableMenuCommand
// --- system code
#31	0x00d01493 in wxMenuBar::MacInstallMenuBar
#32	0x00cdf25e in wxFrame::AttachMenuBar
#33	0x00da7411 in wxFrameBase::SetMenuBar
#34	0x0010e789 in MainWindow::BuildMenus at MainWindow.cpp:253
#35	0x0010f102 in MainWindow::MainWindow at MainWindow.cpp:207
#36	0x0018a253 in MyApp::OnAppStartupEvt at MyApp.cpp:302
// ... more init methods in my code
#45	0x00509d7b in wxMyApp::OnInit at wxMyApp.cpp:121
#46	0x0018b26a in wxAppConsole::CallOnInit at app.h:76
#47	0x00c2399e in wxEntry
#48	0x0018b1f4 in main at MyApp.cpp:70
#49	0x000028d6 in start
I can hack around the problem in my global operator delete using this really disgusting hack, which seems to work:

Code: Select all

// because malloc allocates memory aligned on a 16 byte boundary
// if this block is not misaligned exactly as expected
if( reinterpret_cast< unsigned int >( obj ) % 16 == 0 )
{
	// just free and return
	free( obj );
	return;
}
This seems like a really bad idea, but my product's performance is degraded without my customized memory allocator.

I normally compile as a Universal binary for 10.4 and later (32 bit of course). The only other similar case I have found was with a different library. On this link, someone else had the same issue with a different library:

http://www.bannister.org/forums/ubbthre ... 173&page=3

The problem happens at the same point in that MenuData destructor. On advice from that post, I tried building both wxWidgets and my system using gcc-4.2 for the 10.5 SDK, but that didn't help.

Any ideas?

Thanks
-robin

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Wed May 19, 2010 4:48 pm

Hi,

I don't have any direct clue, except to look at the wxMac code and try to see where is the error.
If no one else on this forum has a better idea, I would recommend posting to the mailing list, where the author of wxMac can probably help you
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply