wxListCtrl crash under OSX 10.14

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
Mark Miles
Earned a small fee
Earned a small fee
Posts: 18
Joined: Sun Jul 20, 2014 9:24 pm

wxListCtrl crash under OSX 10.14

Post by Mark Miles » Wed May 29, 2019 11:48 pm

I was almost done with my app, after almost a week of work, only to find out that OSX 10.14 crashes while I call the method wxListCtrl::SetItem(), the crash occurs randomly, sometimes after the first 2 or 3 items that I add to the list, sometimes after dozens of lines.

Here's an excerpt of the crash log:

Code: Select all

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_malloc.dylib        	0x00007fff5c9513eb nanov2_allocate_from_block + 615
1   libsystem_malloc.dylib        	0x00007fff5c950a61 nanov2_allocate + 130
2   libsystem_malloc.dylib        	0x00007fff5c9518d5 nanov2_calloc + 81
3   libsystem_malloc.dylib        	0x00007fff5c946540 malloc_zone_calloc + 99
4   libsystem_malloc.dylib        	0x00007fff5c9464c0 calloc + 30
5   libobjc.A.dylib               	0x00007fff5afc61de class_createInstance + 83
6   libobjc.A.dylib               	0x00007fff5afc99f4 _objc_rootAlloc + 45
7   com.apple.AppKit              	0x00007fff2e721fad -[NSView(NSInternal) _setupFocusStateForDrawing] + 43
8   com.apple.AppKit              	0x00007fff2df7509a -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:shouldChangeFontReferenceColor:stopAtLayerBackedViews:] + 2633
9   com.apple.AppKit              	0x00007fff2df7463f __46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke + 192
10  com.apple.AppKit              	0x00007fff2df7439c -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 1720
11  com.apple.QuartzCore          	0x00007fff3b278932 CABackingStoreUpdate_ + 577
12  com.apple.QuartzCore          	0x00007fff3b2da2f1 invocation function for block in CA::Layer::display_() + 53
13  com.apple.QuartzCore          	0x00007fff3b277b24 -[CALayer _display] + 1830
14  com.apple.AppKit              	0x00007fff2df7394e _NSBackingLayerDisplay + 528
15  com.apple.AppKit              	0x00007fff2df57e4f -[_NSViewBackingLayer display] + 811
16  com.apple.QuartzCore          	0x00007fff3b277055 CA::Layer::display_if_needed(CA::Transaction*) + 627
17  com.apple.QuartzCore          	0x00007fff3b26527a CA::Context::commit_transaction(CA::Transaction*) + 342
18  com.apple.QuartzCore          	0x00007fff3b2648c2 CA::Transaction::commit() + 588
19  com.apple.AppKit              	0x00007fff2df4ea4d __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
20  com.apple.CoreFoundation      	0x00007fff30832734 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
21  com.apple.CoreFoundation      	0x00007fff30832669 __CFRunLoopDoObservers + 451
22  com.apple.CoreFoundation      	0x00007fff307d51fe __CFRunLoopRun + 1143
23  com.apple.CoreFoundation      	0x00007fff307d4b35 CFRunLoopRunSpecific + 459
24  com.apple.HIToolbox           	0x00007fff2fab396b RunCurrentEventLoopInMode + 292
25  com.apple.HIToolbox           	0x00007fff2fab36a5 ReceiveNextEventCommon + 603
26  com.apple.HIToolbox           	0x00007fff2fab3436 _BlockUntilNextEventMatchingListInModeWithFilter + 64
27  com.apple.AppKit              	0x00007fff2de4d987 _DPSNextEvent + 965
28  com.apple.AppKit              	0x00007fff2de4c71f -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
29  com.apple.AppKit              	0x00007fff2de4683c -[NSApplication run] + 699
30  com.genuinesoundware.DMC-122_Editor	0x00000001053aaf1f wxGUIEventLoop::OSXDoRun() + 207 (evtloop.mm:304)
31  com.genuinesoundware.DMC-122_Editor	0x00000001052e7ed1 wxCFEventLoop::DoRun() + 49 (evtloop_cf.cpp:331)
32  com.genuinesoundware.DMC-122_Editor	0x000000010524238e wxEventLoopBase::Run() + 158 (evtloopcmn.cpp:90)
33  com.genuinesoundware.DMC-122_Editor	0x000000010520fb53 wxAppConsoleBase::MainLoop() + 99 (appbase.cpp:380)
34  com.genuinesoundware.DMC-122_Editor	0x000000010536c2aa wxApp::OnRun() + 26 (app.cpp:366)
35  com.genuinesoundware.DMC-122_Editor	0x0000000105286e88 wxEntry(int&, wchar_t**) + 56 (init.cpp:507)
36  com.genuinesoundware.DMC-122_Editor	0x0000000105203c34 main + 20 (main.cpp:105)
37  libdyld.dylib                 	0x00007fff5c7993d5 start + 1
Trying to set mac.listctrl.always_use_generic to 1 or 0 makes no difference.

Any clue?

User avatar
doublemax
Moderator
Moderator
Posts: 13909
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl crash under OSX 10.14

Post by doublemax » Thu May 30, 2019 12:12 am

Are there multiple threads involved in this part? Can you show the respective code where the crash happens?
Use the source, Luke!

Mark Miles
Earned a small fee
Earned a small fee
Posts: 18
Joined: Sun Jul 20, 2014 9:24 pm

Re: wxListCtrl crash under OSX 10.14

Post by Mark Miles » Thu May 30, 2019 11:22 am

As you suggest, the problem might be caused by a race condition between the thread that adds items to the wxListCtrl and the App's main thread that processes the event queue. This might also be related to my other post about the missing Refresh() of a wxFrame.

The real question is: why am I experiencing this issue only in OSX, partly Windows 10 and only now that I'm using wx3.1.2?
This does not happen in Windows 7, and did not happen when the same code was compiled with wx2.8 and running in any OSX version up to 10.14.

The reason why I am re-compiling this app with wx3.x is because Apple has officially announced that "Mojave" will be the last OSX version to support 32 bit apps. Otherwise my app was perfect as it was and did not need any update.

Mark Miles
Earned a small fee
Earned a small fee
Posts: 18
Joined: Sun Jul 20, 2014 9:24 pm

Re: wxListCtrl crash under OSX 10.14

Post by Mark Miles » Thu May 30, 2019 11:46 am

Just tried to Freeze() the frame before adding any item to the wxListCtrl, and Thaw() at the end, nothing changes, still crashes under OSX.

I assume that Freeze() and Thaw(), in this case, act as semaphores to lock the wxEVT_UPDATE_UI.

I have added an event in my table:

Code: Select all

	EVT_UPDATE_UI(WINDOW_ID_MAIN,		MainWindow::ForceRedraw)
And the function ForceRedraw() does this:

Code: Select all

void MainWindow::ForceRedraw(wxUpdateUIEvent &event)
{
	// Update the main window
	this->Refresh();
	
	// Update the Velocity Curve window
	if (pnCustomCurve->IsVisible()) 
		pnCustomCurve->Refresh();
	
	// Update the Library Window
	if (pnLibrary->IsVisible()) 
		pnLibrary->Refresh();
}
Of course I had to add some preprocessor swiches to have this code only for the OSX version, which will fix the Refresh() problem. Compiling with this code on Windows will cause a terrible flickering of those three windows.

This solves the problem with the curve window not updating after the SetValue() methods have been called on the sliders, and also the wxListCtrl not updating after items were appended, but the program now still crashes at random intervals when an item is appended to the list.

I have also tried to append item locally, i.e. in the same thread... The crashes sill occour. So this seems completely unrelated to the all multi-threading stuff.

User avatar
doublemax
Moderator
Moderator
Posts: 13909
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl crash under OSX 10.14

Post by doublemax » Thu May 30, 2019 12:01 pm

Like i wrote in the other post, i'm not a big fan of EVT_UPDATE_UI. I'd never use it and honestly i think it shouldn't exist.

Please check if this code creates some kind of recursion and if yes, but a recursion guard in that method.
Use the source, Luke!

Post Reply