Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing wx.dataview.TreeListCtrl via DeleteAllItems raises segmentation fault on GTK #679

Closed
simon2x opened this issue Jan 11, 2018 · 5 comments · Fixed by #699
Closed

Comments

@simon2x
Copy link
Contributor

simon2x commented Jan 11, 2018

Operating system: Xubuntu 16.04
wxPython version: 4.0.0a2.dev3038+953a2e5 (GTK3)
Python version: 3.5.2

Description of the problem:

Below is an example of multiple TreeListCtrl's and buttons to clear the respective list.

However, calling DeleteAllItems() from the first added TreeListCtrl crashes the app and "raise a segmentation fault (core dumped)"

But the other TreeListCtrl's seem to work fine.

import wx
import wx.dataview
 
class Main(wx.Frame):
    
    def __init__(self):
        wx.Frame.__init__(self, None)
        
        panel = wx.Panel(self)   
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.tree1 = wx.dataview.TreeListCtrl(panel)
        self.tree1.AppendColumn("column")
        hsizer.Add(self.tree1, 1, wx.ALL|wx.EXPAND, 10)   
        
        self.tree2 = wx.dataview.TreeListCtrl(panel)
        self.tree2.AppendColumn("column")
        hsizer.Add(self.tree2, 1, wx.ALL|wx.EXPAND, 10)   
        
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.tree3 = wx.dataview.TreeListCtrl(panel)
        self.tree3.AppendColumn("column")
        hsizer2.Add(self.tree3, 1, wx.ALL|wx.EXPAND, 10)  
        
        self.tree4 = wx.dataview.TreeListCtrl(panel)
        self.tree4.AppendColumn("column")
        hsizer2.Add(self.tree4, 1, wx.ALL|wx.EXPAND, 10)  
        
        for x in range(10):
            item = self.tree1.AppendItem(self.tree1.GetRootItem(), str(x))
            item = self.tree2.AppendItem(self.tree2.GetRootItem(), str(x))
            item = self.tree3.AppendItem(self.tree3.GetRootItem(), str(x))
            item = self.tree4.AppendItem(self.tree4.GetRootItem(), str(x))
            
        btn = wx.Button(panel, label="Clear 1st List")    
        btn.Bind(wx.EVT_BUTTON, self.OnButton1)
        hsizer.Add(btn, 1, wx.ALL|wx.EXPAND, 10)  
        
        btn = wx.Button(panel, label="Clear 2nd List")   
        btn.Bind(wx.EVT_BUTTON, self.OnButton2)
        hsizer.Add(btn, 1, wx.ALL|wx.EXPAND, 10) 
        
        btn = wx.Button(panel, label="Clear 3rd List")    
        btn.Bind(wx.EVT_BUTTON, self.OnButton3)
        hsizer2.Add(btn, 1, wx.ALL|wx.EXPAND, 10)  
        
        btn = wx.Button(panel, label="Clear 4th List")   
        btn.Bind(wx.EVT_BUTTON, self.OnButton4)
        hsizer2.Add(btn, 1, wx.ALL|wx.EXPAND, 10) 
        
        sizer.Add(hsizer, 1, wx.ALL|wx.EXPAND, 0)   
        sizer.Add(hsizer2, 1, wx.ALL|wx.EXPAND, 0)  
        
        panel.SetSizer(sizer)
        sizer.Fit(self)
        self.SetSize((600,700))
        self.Show()
        self.Centre() 
        
    def OnButton1(self, event):
        self.tree1.DeleteAllItems()
        
    def OnButton2(self, event):
        self.tree2.DeleteAllItems()
        
    def OnButton3(self, event):
        self.tree3.DeleteAllItems()    
        
    def OnButton4(self, event):
        self.tree4.DeleteAllItems()   
        
if __name__ == "__main__":
    app = wx.App()
    Main()
    app.MainLoop()
@simon2x
Copy link
Contributor Author

simon2x commented Jan 11, 2018

Tried to manually delete all items. Seems to fail when trying to GetNextItem. For example:

def OnButton1(self, event):
    item = self.tree1.GetFirstItem()
    while item.IsOk():
         self.tree1.DeleteItem(item)
         break # toggle this comment
         item = self.tree1.GetNextItem(item)

@RobinD42
Copy link
Member

Not sure why it is crashing yet, but this works for a workaround:

    def OnButton1(self, event):
        item = self.tree1.GetFirstItem()
        while item:
            self.tree1.DeleteItem(item)
            item = self.tree1.GetFirstItem()

When the first has been deleted, "next" is undefined, but we do know that it will now be the new "first".

@simon2x
Copy link
Contributor Author

simon2x commented Jan 13, 2018

With gdb:

(gdb) run test.py 
Starting program: /usr/bin/python3 test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe6287700 (LWP 4666)]
[New Thread 0x7fffe5a86700 (LWP 4667)]

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
__memcpy_sse2 () at ../sysdeps/x86_64/multiarch/../memcpy.S:402
402	../sysdeps/x86_64/multiarch/../memcpy.S: No such file or directory.

And full backtrace:

(gdb) bt
#0  __memcpy_sse2 () at ../sysdeps/x86_64/multiarch/../memcpy.S:402
#1  0x00007fffe94de147 in void std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_M_construct<wchar_t const*>(wchar_t const*, wchar_t const*, std::forward_iterator_tag) () from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_adv-3.0.so.0
#2  0x00007fffe9572e37 in wxTreeListModel::GetValue(wxVariant&, wxDataViewItem const&, unsigned int) const () from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_adv-3.0.so.0
#3  0x00007fffe959f9fb in wxGtkTreeCellDataFunc ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_adv-3.0.so.0
#4  0x00007ffff38b331b in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#5  0x00007ffff25f5340 in g_hash_table_foreach () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#6  0x00007ffff38b31ab in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#7  0x00007ffff38b87a9 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#8  0x00007ffff39a3a43 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#9  0x00007ffff28dd1d4 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#10 0x00007ffff28f79a6 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#11 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#12 0x00007ffff38b4d16 in gtk_cell_area_apply_attributes ()
   from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#13 0x00007ffff3828aed in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#14 0x00007ffff3828bf8 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#15 0x00007ffff382b033 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#16 0x00007ffff3ac2032 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#17 0x00007ffff3ac5706 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#18 0x00007ffff28dcfa5 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#19 0x00007ffff28eefc1 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#20 0x00007ffff28f7d5c in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#21 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#22 0x00007fffe95982be in wxGtkDataViewModelNotifier::Cleared() ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_adv-3.0.so.0
#23 0x00007fffe94e0c82 in wxDataViewModel::Cleared() ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_adv-3.0.so.0
#24 0x00007fffe9860302 in meth_wxTreeListCtrl_DeleteAllItems.lto_priv.351 ()
   from /usr/local/lib/python3.5/dist-packages/wx/_dataview.cpython-35m-x86_64-linux-gnu.so
#25 0x00000000004e9b7f in PyCFunction_Call ()
#26 0x00000000005372f4 in PyEval_EvalFrameEx ()
#27 0x0000000000540f9b in PyEval_EvalCodeEx ()
#28 0x00000000004ebd23 in ?? ()
#29 0x00000000005c1797 in PyObject_Call ()
#30 0x00000000004fb9ce in ?? ()
#31 0x00000000005c1797 in PyObject_Call ()
#32 0x0000000000534d90 in PyEval_CallObjectWithKeywords ()
#33 0x00007ffff62c0147 in wxPyCallback::EventThunker(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/_core.cpython-35m-x86_64-linux-gnu.so
---Type <return> to continue, or q <return> to quit---
#34 0x00007ffff4d4449e in wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const () from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#35 0x00007ffff4eca607 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#36 0x00007ffff4eca9ee in wxEvtHandler::SearchDynamicEventTable(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#37 0x00007ffff4ecaa7f in wxEvtHandler::TryHereOnly(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#38 0x00007ffff4ecab33 in wxEvtHandler::ProcessEventLocally(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#39 0x00007ffff4ecab95 in wxEvtHandler::ProcessEvent(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#40 0x00007ffff637dedc in sipwxButton::ProcessEvent(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/_core.cpython-35m-x86_64-linux-gnu.so
#41 0x00007ffff4eca907 in wxEvtHandler::SafelyProcessEvent(wxEvent&) ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#42 0x00007ffff56a73b7 in wxgtk_button_clicked_callback ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_core-3.0.so.0
#43 0x00007ffff28dd1d4 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#44 0x00007ffff28f79a6 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#45 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#46 0x00007ffff38aa6ad in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#47 0x00007ffff38aa715 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#48 0x00007ffff28dd1d4 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#49 0x00007ffff28f79a6 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#50 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#51 0x00007ffff38a87a0 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#52 0x00007fffed566e40 in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#53 0x00007fffed5668ab in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#54 0x00007ffff28ddcf5 in g_cclosure_marshal_generic_va ()
   from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#55 0x00007ffff28dd1d4 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#56 0x00007ffff28f79a6 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#57 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#58 0x00007ffff3956891 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#59 0x00007ffff28dfdbe in g_cclosure_marshal_VOID__BOXEDv ()
   from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#60 0x00007ffff28dd1d4 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#61 0x00007ffff28f79a6 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#62 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#63 0x00007ffff3953bee in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#64 0x00007ffff395522b in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#65 0x00007ffff3957de5 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
#66 0x00007ffff3927beb in gtk_event_controller_handle_event ()
   from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#67 0x00007ffff3ad8bfb in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#68 0x00007ffff399cfac in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#69 0x00007ffff28dcfa5 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#70 0x00007ffff28ef56e in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#71 0x00007ffff28f77f9 in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#72 0x00007ffff28f808f in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#73 0x00007ffff3adac3c in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#74 0x00007ffff399a3be in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#75 0x00007ffff399c1bc in gtk_main_do_event () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#76 0x00007ffff3509d92 in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#77 0x00007ffff2606197 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#78 0x00007ffff26063f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#79 0x00007ffff2606712 in g_main_loop_run () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#80 0x00007ffff399b395 in gtk_main () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#81 0x00007ffff5645295 in wxGUIEventLoop::DoRun() ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_gtk3u_core-3.0.so.0
#82 0x00007ffff4d85e53 in wxEventLoopBase::Run() ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#83 0x00007ffff4d4b086 in wxAppConsoleBase::MainLoop() ()
   from /usr/local/lib/python3.5/dist-packages/wx/libwx_baseu-3.0.so.0
#84 0x00007ffff60dd854 in wxPyApp::MainLoop() ()
   from /usr/local/lib/python3.5/dist-packages/wx/_core.cpython-35m-x86_64-linux-gnu.so
#85 0x00007ffff60e0845 in meth_wxPyApp_MainLoop.lto_priv.24318 ()
   from /usr/local/lib/python3.5/dist-packages/wx/_core.cpython-35m-x86_64-linux-gnu.so
#86 0x00000000004e9b7f in PyCFunction_Call ()
#87 0x00000000005372f4 in PyEval_EvalFrameEx ()
#88 0x000000000053b7e4 in PyEval_EvalFrameEx ()
#89 0x0000000000540199 in ?? ()
#90 0x0000000000540e4f in PyEval_EvalCode ()
#91 0x000000000060c272 in ?? ()
#92 0x000000000060e71a in PyRun_FileExFlags ()
#93 0x000000000060ef0c in PyRun_SimpleFileExFlags ()
#94 0x000000000063fb26 in Py_Main ()
#95 0x00000000004cfeb1 in main ()
(gdb) 

@RobinD42
Copy link
Member

RobinD42 commented Jan 16, 2018

Superficially this seems like the same as this issue: http://trac.wxwidgets.org/ticket/12327, however it was fixed 7 years ago, and the code updated by the fix is still the same as that change. Also, while investigating I've had it crash for different reasons at different places so it would seem that something is getting trashed well before the crash actually happens and depending on the trash the crash behavior is different.

Still looking...

@RobinD42
Copy link
Member

I was able to duplicate the problem in C++ so I've filed a new ticket: https://trac.wxwidgets.org/ticket/18045

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants