Opened 6 months ago

Closed 6 months ago

#15575 closed defect (fixed)

OSX: wxTreeListCtrl crashes when deleting and item(s) (wx3.0RC1)

Reported by: eran Owned by: vadz
Priority: high Milestone: 3.0.0
Component: wxOSX-Cocoa Version: 3.0.0-rc1
Keywords: wxTreeListCtrl OSX crash Cc:
Blocked By: Blocking:
Patch: no

Description

Hi,

Attempting to delete the selected item (or items in case of multiple selection tree)
results in a crash

The same code works perfectly under Windows/Linux
I am using OSX 10.8.4
wxWidgets 3.0RC-1 (OSX Cocoa)

This is easily reproducible with the treelist sample (in my case I replaced the content of the function OnDumpSelection() with the following:

void MyFrame::OnDumpSelection(wxCommandEvent& WXUNUSED(event))
{
    if ( m_treelist->HasFlag(wxTL_MULTIPLE) )
    {
        wxTreeListItems selections;
        const unsigned numSelected = m_treelist->GetSelections(selections);

for(size_t i=0; i<numSelected; ++i) {
        m_treelist->DeleteItem( selections.at(i) );
}
    }
    else // Single selection
    {
        m_treelist->DeleteItem( m_treelist->GetSelection()  );
    }
}

This is 100% reproducible
Eran

Change History (7)

comment:1 Changed 6 months ago by vadz

Would you have a backtrace for this crash?

comment:2 Changed 6 months ago by eran

I will add one once I will get back home (where I have my Mac machine)

Eran

comment:3 Changed 6 months ago by eran

Sorry for the late reply, here is the backtrace:

Process:         treelist [319]
Path:            /Users/USER/*/treelist.app/Contents/MacOS/treelist
Identifier:      org.wxwindows.samples.treelist
Version:         3.0.0 (3.0.0)
Code Type:       X86-64 (Native)
Parent Process:  launchd [232]
User ID:         501

Date/Time:       2013-10-18 03:19:53.252 -0700
OS Version:      Mac OS X 10.8 (12A269)
Report Version:  10
Sleep/Wake UUID: 0063DB4A-2580-4204-8EA4-1736CD7A06A3

Interval Since Last Report:          652221 sec
Crashes Since Last Report:           1103
Per-App Interval Since Last Report:  196 sec
Per-App Crashes Since Last Report:   2
Anonymous UUID:                      A071456E-1273-4AD1-8D0D-EDC104F2DE7D

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libstdc++.6.dylib             	0x00007fff944b1d48 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_grab(std::allocator<wchar_t> const&, std::allocator<wchar_t> const&) + 4
1   libstdc++.6.dylib             	0x00007fff944b2364 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::std::basic_string(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) + 32
2   libwx_osx_cocoau-3.0.0.0.0.dylib	0x0000000100356ff4 wxDataViewIconText::wxDataViewIconText(wxString const&, wxIcon const&) + 44
3   libwx_osx_cocoau-3.0.0.0.0.dylib	0x0000000100354fd7 wxTreeListModel::GetValue(wxVariant&, wxDataViewItem const&, unsigned int) const + 385
4   libwx_osx_cocoau-3.0.0.0.0.dylib	0x0000000100364c4e -[wxCocoaOutlineDataSource outlineView:objectValueForTableColumn:byItem:] + 174
5   com.apple.AppKit              	0x00007fff9597a7f4 -[NSTableView preparedCellAtColumn:row:] + 416
6   com.apple.AppKit              	0x00007fff9597a45c -[NSOutlineView preparedCellAtColumn:row:] + 56
7   com.apple.AppKit              	0x00007fff9597a367 -[NSTableView _drawContentsAtRow:column:withCellFrame:] + 47
8   com.apple.AppKit              	0x00007fff9597a2db -[NSOutlineView _drawContentsAtRow:column:withCellFrame:] + 94
9   com.apple.AppKit              	0x00007fff95978d9e -[NSTableView drawRow:clipRect:] + 2131
10  com.apple.AppKit              	0x00007fff95968c93 -[NSTableView drawRowIndexes:clipRect:] + 397
11  com.apple.AppKit              	0x00007fff95968af1 -[NSOutlineView drawRowIndexes:clipRect:] + 113
12  com.apple.AppKit              	0x00007fff95967676 -[NSTableView drawRect:] + 1269
13  com.apple.AppKit              	0x00007fff9584bb70 -[NSView _drawRect:clip:] + 4437
14  com.apple.AppKit              	0x00007fff958489e3 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 3058
15  com.apple.AppKit              	0x00007fff95849474 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5763
16  com.apple.AppKit              	0x00007fff95849474 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5763
17  com.apple.AppKit              	0x00007fff95849474 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5763
18  com.apple.AppKit              	0x00007fff95849474 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5763
19  com.apple.AppKit              	0x00007fff95849474 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5763
20  com.apple.AppKit              	0x00007fff95847b73 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 314
21  com.apple.AppKit              	0x00007fff9584379d -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 4675
22  com.apple.AppKit              	0x00007fff9580d703 -[NSView displayIfNeeded] + 1830
23  com.apple.AppKit              	0x00007fff9580cc3c _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 738
24  com.apple.AppKit              	0x00007fff95dd4c81 __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke_01208 + 46
25  com.apple.CoreFoundation      	0x00007fff954d20c7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
26  com.apple.CoreFoundation      	0x00007fff954d2031 __CFRunLoopDoObservers + 369
27  com.apple.CoreFoundation      	0x00007fff954ad4a8 __CFRunLoopRun + 728
28  com.apple.CoreFoundation      	0x00007fff954acdd2 CFRunLoopRunSpecific + 290
29  com.apple.AppKit              	0x00007fff95a2f6ab -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 150
30  com.apple.AppKit              	0x00007fff9571c86f -[NSMenu _internalPerformActionForItemAtIndex:] + 36
31  com.apple.AppKit              	0x00007fff9571c6f7 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 135
32  com.apple.AppKit              	0x00007fff95a287b5 NSSLMMenuEventHandler + 342
33  com.apple.HIToolbox           	0x00007fff89e5a5ba DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1206
34  com.apple.HIToolbox           	0x00007fff89e59a89 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 410
35  com.apple.HIToolbox           	0x00007fff89e6f871 SendEventToEventTarget + 40
36  com.apple.HIToolbox           	0x00007fff89ea63a9 SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) + 443
37  com.apple.HIToolbox           	0x00007fff89e4b2b1 SendMenuCommandWithContextAndModifiers + 59
38  com.apple.HIToolbox           	0x00007fff89e4b263 SendMenuItemSelectedEvent + 254
39  com.apple.HIToolbox           	0x00007fff89e4b0ef FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*) + 94
40  com.apple.HIToolbox           	0x00007fff89e2714b MenuSelectCore(MenuData*, Point, double, unsigned int, OpaqueMenuRef**, unsigned short*) + 605
41  com.apple.HIToolbox           	0x00007fff89e26758 _HandleMenuSelection2 + 565
42  com.apple.AppKit              	0x00007fff958e8183 _NSHandleCarbonMenuEvent + 245
43  com.apple.AppKit              	0x00007fff9580a50f _DPSNextEvent + 2073
44  com.apple.AppKit              	0x00007fff95809862 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
45  com.apple.AppKit              	0x00007fff95800c03 -[NSApplication run] + 517
46  libwx_osx_cocoau-3.0.0.0.0.dylib	0x00000001001a9d9e wxGUIEventLoop::OSXDoRun() + 114
47  libwx_osx_cocoau-3.0.0.0.0.dylib	0x00000001000da7c4 wxCFEventLoop::DoRun() + 50
48  libwx_osx_cocoau-3.0.0.0.0.dylib	0x0000000100054cb7 wxEventLoopBase::Run() + 83
49  libwx_osx_cocoau-3.0.0.0.0.dylib	0x000000010002e7f2 wxAppConsoleBase::MainLoop() + 128
50  libwx_osx_cocoau-3.0.0.0.0.dylib	0x0000000100153f1b wxApp::OnRun() + 29
51  libwx_osx_cocoau-3.0.0.0.0.dylib	0x000000010007dee6 wxEntry(int&, wchar_t**) + 102
52  org.wxwindows.samples.treelist	0x0000000100001b84 main + 20
53  org.wxwindows.samples.treelist	0x0000000100001b44 start + 52

This is how I built wxWidgets:
../configure --with-osx_cocoa --disable-debug --enable-shared --enable-monolithic

comment:4 Changed 6 months ago by eran

In the mean while, I will build wx in debug mode, hopefully we will get a more useful backtrace
Eran

comment:5 Changed 6 months ago by eran

Running it under gdb gives this backtrace:

../src/common/list.cpp(317): assert "Assert failure" failed in Item(): invalid index in wxListBase::Item
Collecting stack trace information, please wait...
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007fff93467d46 in __kill ()
(gdb) bt
#0  0x00007fff93467d46 in __kill ()
#1  0x000000010002dbf6 in wxDefaultAssertHandler ()
#2  0x000000010002dee1 in wxOnAssert ()
#3  0x0000000100097524 in wxListBase::Item ()
#4  0x000000010014963e in wxImageList::GetIcon ()
#5  0x00000001003c4e7e in wxTreeListModel::GetValue ()
#6  0x00000001003d6c15 in -[wxCocoaOutlineDataSource outlineView:objectValueForTableColumn:byItem:] ()
#7  0x00007fff9597a7f4 in -[NSTableView preparedCellAtColumn:row:] ()
#8  0x00007fff9597a45c in -[NSOutlineView preparedCellAtColumn:row:] ()
#9  0x00007fff95797780 in -[NSTableView _dirtyVisibleCellsForKeyStateChange] ()
#10 0x00007fff95796be9 in -[NSTableView _windowChangedKeyState] ()
#11 0x00007fff955040b6 in __NSArrayEnumerate ()
#12 0x00007fff958c532b in -[NSView _windowChangedKeyState] ()
#13 0x00007fff955040b6 in __NSArrayEnumerate ()
#14 0x00007fff958c532b in -[NSView _windowChangedKeyState] ()
#15 0x00007fff955040b6 in __NSArrayEnumerate ()
#16 0x00007fff958c532b in -[NSView _windowChangedKeyState] ()
#17 0x00007fff955040b6 in __NSArrayEnumerate ()
#18 0x00007fff958c532b in -[NSView _windowChangedKeyState] ()
#19 0x00007fff955040b6 in __NSArrayEnumerate ()
#20 0x00007fff958c532b in -[NSView _windowChangedKeyState] ()
#21 0x00007fff958c5215 in -[NSFrameView _windowChangedKeyState] ()
#22 0x00007fff958c4cae in -[NSWindow _setFrameNeedsDisplay:] ()
#23 0x00007fff958c29de in -[NSWindow _changeKeyAndMainLimitedOK:] ()
#24 0x00007fff958c218b in -[NSWindow _makeKeyRegardlessOfVisibility] ()
#25 0x00007fff957028d4 in -[NSApplication _orderFrontModalWindow:relativeToWindow:] ()
#26 0x00007fff957021df in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] ()
#27 0x00007fff95a541e7 in -[NSApplication beginModalSessionForWindow:] ()
#28 0x00007fff95a53d9a in -[NSApplication runModalForWindow:] ()
#29 0x00007fff95a46984 in -[NSAlert runModal] ()
#30 0x00000001001f0845 in wxMessageDialog::ShowModal ()
#31 0x000000010012a8d0 in wxMessageBox ()
#32 0x000000010020bcc2 in wxGUIAppTraitsBase::ShowAssertDialog ()
#33 0x000000010002ec02 in ShowAssertDialog ()
#34 0x000000010002ef8e in wxAppConsoleBase::OnAssertFailure ()
#35 0x000000010002dc6a in wxDefaultAssertHandler ()
#36 0x000000010002dee1 in wxOnAssert ()
#37 0x0000000100097524 in wxListBase::Item ()
#38 0x000000010014963e in wxImageList::GetIcon ()
#39 0x00000001003c4e7e in wxTreeListModel::GetValue ()
#40 0x00000001003d6c15 in -[wxCocoaOutlineDataSource outlineView:objectValueForTableColumn:byItem:] ()
#41 0x00007fff9597a7f4 in -[NSTableView preparedCellAtColumn:row:] ()
#42 0x00007fff9597a45c in -[NSOutlineView preparedCellAtColumn:row:] ()
#43 0x00007fff9597a367 in -[NSTableView _drawContentsAtRow:column:withCellFrame:] ()
#44 0x00007fff9597a2db in -[NSOutlineView _drawContentsAtRow:column:withCellFrame:] ()
#45 0x00007fff95978d9e in -[NSTableView drawRow:clipRect:] ()
#46 0x00007fff95968c93 in -[NSTableView drawRowIndexes:clipRect:] ()
#47 0x00007fff95968af1 in -[NSOutlineView drawRowIndexes:clipRect:] ()
#48 0x00007fff95967676 in -[NSTableView drawRect:] ()
#49 0x00007fff9584bb70 in -[NSView _drawRect:clip:] ()
#50 0x00007fff958489e3 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#51 0x00007fff95849474 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#52 0x00007fff95849474 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#53 0x00007fff95849474 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#54 0x00007fff95849474 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#55 0x00007fff95849474 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#56 0x00007fff95847b73 in -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#57 0x00007fff9584379d in -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
#58 0x00007fff9580d703 in -[NSView displayIfNeeded] ()
#59 0x00007fff9580cc3c in _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints ()
#60 0x00007fff95dd4c81 in __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke_01208 ()
#61 0x00007fff954d20c7 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#62 0x00007fff954d2031 in __CFRunLoopDoObservers ()
#63 0x00007fff954ad4a8 in __CFRunLoopRun ()
#64 0x00007fff954acdd2 in CFRunLoopRunSpecific ()
#65 0x00007fff95a2f6ab in -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] ()
#66 0x00007fff9571c86f in -[NSMenu _internalPerformActionForItemAtIndex:] ()
#67 0x00007fff9571c6f7 in -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] ()
#68 0x00007fff95a287b5 in NSSLMMenuEventHandler ()
#69 0x00007fff89e5a5ba in DispatchEventToHandlers ()
#70 0x00007fff89e59a89 in SendEventToEventTargetInternal ()
#71 0x00007fff89e6f871 in SendEventToEventTarget ()
#72 0x00007fff89ea63a9 in SendHICommandEvent ()
#73 0x00007fff89e4b2b1 in SendMenuCommandWithContextAndModifiers ()
#74 0x00007fff89e4b263 in SendMenuItemSelectedEvent ()
#75 0x00007fff89e4b0ef in FinishMenuSelection ()
#76 0x00007fff89e2714b in MenuSelectCore ()
#77 0x00007fff89e26758 in _HandleMenuSelection2 ()
#78 0x00007fff958e8183 in _NSHandleCarbonMenuEvent ()
#79 0x00007fff9580a50f in _DPSNextEvent ()
#80 0x00007fff95809862 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#81 0x00007fff95800c03 in -[NSApplication run] ()
#82 0x00000001001e8c0e in wxGUIEventLoop::OSXDoRun ()
#83 0x00000001000fc364 in wxCFEventLoop::DoRun ()
#84 0x000000010005e817 in wxEventLoopBase::Run ()
#85 0x000000010002f256 in wxAppConsoleBase::MainLoop ()
#86 0x000000010018bfab in wxApp::OnRun ()
#87 0x000000010008f206 in wxEntry ()
#88 0x0000000100001184 in main ()

Note the 'assert' at the top of the backtrace

../src/common/list.cpp(317): assert "Assert failure" failed in Item(): invalid index in wxListBase::Item

Eran

comment:6 Changed 6 months ago by vadz

  • Owner set to vadz
  • Status changed from new to accepted

Thanks, I see the bug and got a fix, will commit soon.

comment:7 Changed 6 months ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [75044]) Fix ItemDeleted() call in wxTreeListModel.

While it doesn't matter when exactly do we call it with the generic or GTK
native implementations, under OS X we must update the internal model first and
call this method afterwards because it refreshes the control contents
immediately and so was calling back to the model and getting the pointer to
the item about to be deleted, which resulted in a crash when this pointer was
dereferences later.

Closes #15575.

Note: See TracTickets for help on using tickets.