Author Topic: Crash when unloading compiler plugin  (Read 16123 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Crash when unloading compiler plugin
« on: April 29, 2012, 05:50:46 pm »
I'm playing a bit with the plugins and I found a rather strange crash.

To reproduce:
1. Open codeblocks
2. Open Plugins -> Manager ...
3. Unload the compiler plugin
4. Load the compiler plugin
5. Unload the compiler plugin -> codeblocks crashes

Tested on gentoo linux amd64 wxgtk 2.8.12.x latest trunk version of c::b, compiled in c::b

Here is the backtrace:
Code
#0 0x7ffff497c835	wxWindowBase::TryParent(wxEvent&) () (/usr/lib64/libwx_gtk2u_core-2.8.so.0:??)
#1 0x7ffff420b2b0 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib64/libwx_baseu-2.8.so.0:??)
#2 0x7ffff5737943 wxAuiNotebook::SetSelection(unsigned long) () (/usr/lib64/libwx_gtk2u_aui-2.8.so.0:??)
#3 0x7ffff5739542 wxAuiNotebook::RemovePage(unsigned long) () (/usr/lib64/libwx_gtk2u_aui-2.8.so.0:??)
#4 0x7ffff57396cd wxAuiNotebook::DeletePage(unsigned long) () (/usr/lib64/libwx_gtk2u_aui-2.8.so.0:??)
#5 0x7ffff3c1ff6f cbAuiNotebook::DeletePage(this=0xe7ec00, page=3) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/sdk/cbauibook.cpp:590)
#6 0x4b2b85 InfoPane::DeleteLogger(this=0xe7ec00, l=0x1da7fa0) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/src/infopane.cpp:452)
#7 0x46a1dc MainFrame::OnRemoveLogWindow(this=0xb46220, event=...) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/src/main.cpp:4613)
#8 0x47a0a7 cbEventFunctor<MainFrame, CodeBlocksLogEvent>::Call(this=0x1452810, event=...) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/include/cbfunctor.h:35)
#9 0x7ffff3c21f58 Manager::ProcessEvent(this=0x8775c0, event=...) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/sdk/manager.cpp:211)
#10 0x7fffe212e43d CompilerGCC::OnRelease(this=0x1317100, appShutDown=false) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/plugins/compilergcc/compilergcc.cpp:492)
#11 0x7ffff3c2dfb4 cbPlugin::Release(this=0x1317100, appShutDown=false) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/sdk/cbplugin.cpp:85)
#12 0x7ffff3c62b86 PluginManager::DetachPlugin(this=0x116aa50, plugin=0x1317100) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/sdk/pluginmanager.cpp:207)
#13 0x7ffff3b2622b PluginsConfigurationDlg::OnToggle(this=0x7fffffffc420, event=...) (/home/obfuscated/projects/codeblocks/dev/trunk2/src/sdk/pluginsconfigurationdlg.cpp:200)
#14 0x7ffff420ae56 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (/usr/lib64/libwx_baseu-2.8.so.0:??)
#15 0x7ffff420afdb wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () (/usr/lib64/libwx_baseu-2.8.so.0:??)
#16 0x7ffff420b314 wxEvtHandler::ProcessEvent(wxEvent&) () (/usr/lib64/libwx_baseu-2.8.so.0:??)
#17 0x7ffff497c838 wxWindowBase::TryParent(wxEvent&) () (/usr/lib64/libwx_gtk2u_core-2.8.so.0:??)
#18 0x7ffff48d92e9 ??() (/usr/lib64/libwx_gtk2u_core-2.8.so.0:??)
#19 0x7ffff5c9358e ??() (/usr/lib64/libgobject-2.0.so.0:??)
#20 0x7ffff5cabedd g_signal_emit_valist() (/usr/lib64/libgobject-2.0.so.0:??)
#21 0x7ffff5caca15 g_signal_emit() (/usr/lib64/libgobject-2.0.so.0:??)
#22 0x7ffff7833245 ??() (/usr/lib64/libgtk-x11-2.0.so.0:??)
#23 0x7ffff5c9358e ??() (/usr/lib64/libgobject-2.0.so.0:??)
#24 0x7ffff5cabedd g_signal_emit_valist() (/usr/lib64/libgobject-2.0.so.0:??)
#25 0x7ffff5caca15 g_signal_emit() (/usr/lib64/libgobject-2.0.so.0:??)
#26 0x7ffff7831ffd ??() (/usr/lib64/libgtk-x11-2.0.so.0:??)
#27 0x7ffff78dcba8 ??() (/usr/lib64/libgtk-x11-2.0.so.0:??)
#28 0x7ffff5c932db g_closure_invoke() (/usr/lib64/libgobject-2.0.so.0:??)
#29 0x7ffff5ca4b9d ??() (/usr/lib64/libgobject-2.0.so.0:??)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline frithjofh

  • Regular
  • ***
  • Posts: 376
Re: Crash when unloading compiler plugin
« Reply #1 on: April 29, 2012, 08:53:08 pm »
same confirmed here. SuSE 12.1 on AMD x84_64, wxgtk 2.8.12. code::blocks svn7948 self compiled

[attachment deleted by admin]
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Crash when unloading compiler plugin
« Reply #2 on: April 29, 2012, 10:05:53 pm »
I see why it happens, not sure whether it is am issue in C::B or wxWidgets.
I hope I find a fix soon.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Crash when unloading compiler plugin
« Reply #3 on: April 29, 2012, 11:31:57 pm »
I'll be happy if you explain what is the reason for this :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Crash when unloading compiler plugin
« Reply #4 on: April 30, 2012, 08:38:22 am »
I'll be happy if you explain what is the reason for this :)
Just from the log I'd guess its a deleted pointer that did not get NULLed and is re-used...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Crash when unloading compiler plugin
« Reply #5 on: April 30, 2012, 10:28:21 am »
For some obscure reasons parts of OnRelease will be run twice, if it is called the second time.
The crash happens in wxAuiNotebook::SetSelectionToWindow if m_pLog is deleted first, and in some sizer-releated code, if m_pListLog is deleted first. Butthe crash is just a symptom, there must be a real problem, probably in our code, or with the compiler.

The crash happens with wx2.8 and wx2.9, C::B is compiled with wx4.6 and pch's.
I try it with pch's disabled now.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Crash when unloading compiler plugin
« Reply #6 on: April 30, 2012, 10:58:47 am »
I try it with pch's disabled now.
Exactly the same behaviour.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Crash when unloading compiler plugin
« Reply #7 on: April 30, 2012, 08:23:41 pm »
Using this patch fixes the problem: http://cmpt.benbmp.org/codeblocks/patches/compiler_load_unload.patch

It seems that removing the event handler from the chain in the main window fixes it.
Also by reading the docs of wxEvtHandler, I've found this:
Quote
When using multiple inheritance it is imperative that the wxEvtHandler(-derived) class be the first class inherited such that the "this" pointer for the overall object will be identical to the "this" pointer for the wxEvtHandler portion.
I'm not sure why this is the case, but I've modified the class to obey this rule. There are other cases which violate it, so they need to be fixed, too.
I guess probably they are casting a void pointer or something like that to wxEvtHandler in some of the macros and they rely on this hack.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Crash when unloading compiler plugin
« Reply #8 on: April 30, 2012, 09:27:06 pm »
Good catch !
Your patch works fine here, tested with wx2.9  on debian 64bit.

From my point of view, you should commit it, if it is does not break anything on windows.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Crash when unloading compiler plugin
« Reply #9 on: May 01, 2012, 10:29:43 am »
From my point of view, you should commit it, if it is does not break anything on windows.
I'll try both patches (the other one of the ToDo list plugin) today on Windows. BTW: This is especially "critical" in wx29 as the event handler chain has caused a lot trouble there...I'll report back.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Crash when unloading compiler plugin
« Reply #10 on: May 01, 2012, 01:17:54 pm »
Unfortunately, now I get the following warning with wx2.9.x:
---------------------------
wxWidgets Debug Alert
---------------------------
../../src/common/wincmn.cpp(1448): assert "Assert failure" failed in RemoveEventHandler(): where has the event handler gone?
Do you want to stop the program?
You can also choose [Cancel] to suppress further warnings.

Not nice. :-/
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Crash when unloading compiler plugin
« Reply #11 on: May 01, 2012, 01:25:45 pm »
Same on 64 bit build. I don't thinks that's a good thing to do. Either it is simply wrong, or we screw the event queue somewhere else. Disabling the todo (and compiler) plugin makes the debug messages go away again, so the other core plugins seem to make wx happy.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Crash when unloading compiler plugin
« Reply #12 on: May 01, 2012, 01:45:13 pm »
Morten: Do you see the crash without the patch in cb-wx28? Does it fix it there if there is a crash?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Crash when unloading compiler plugin
« Reply #13 on: May 01, 2012, 02:10:02 pm »
Morten: Do you see the crash without the patch in cb-wx28? Does it fix it there if there is a crash?
wx28: Crash w/o patch, no crash w/ patch. (Win7/64 bit)

EDIT: Maybe you should surround this with if (!Manager::Get()->IsAppShuttingdown()) to fix the assertion failures I see? (I don't recall the method's name exactly, but you get the idea...).
« Last Edit: May 01, 2012, 02:17:31 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Crash when unloading compiler plugin
« Reply #14 on: May 02, 2012, 07:57:13 pm »
Hm, Can you try it yourself and then tell me if it works? Can you try to debug it? Is this debug notification debuggable with wx29 in wx28 they are pretty pointless in release builds at least.

I have no wx29-windows working config and I'm not eager to try it or to try to setup one.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]