Until now I had crashes when middle-clicking on a tab to close some file while building
Aha, that does not explain
ProjectManager20OnTreeItemRightClick, but it hardens the theory of a
wxYield re-entrancy.
For example, the DevPak plugin uses
wxYield in several places.
Worse yet, wxWidgets sometimes calls
wxYield secretly, too!
This line from the code completion plugin:
wxExecute(Command, Output, Errors, wxEXEC_NODISABLE);is a very good candidate for the origin of the crash (especially due to
wxEXEC_NODISABLE).
The same construct appears in a couple of other places, too (for example in
CompilerCommandGenerator::ExpandBackticks).
Unluckily, the solution is not easy, because wxExecute sucks so bad. If you call
wxExecute synchronously, it will run a tight loop around
wxYield, waiting for the pipe to close. This means that the user interface (which runs in the same thread) stays responsive, but at the same time, it means that any other call to
wxYield will crash you if you click a mouse button or anything.
The "solution" to this problem is to simply disable the application window during that time (unless you provide the
wxEXEC_NODISABLE flag).
So basically, you can choose whether you want to risk a crash or whether you prefer your app window changing state all the time and your application hanging dead in space for as long as the background job is running...
A solution that works reliably is to always call wxExecute asynchronously and send the output via the event handler, but that is quite inefficient, and not easy in every case. In some situations, it may even not be possible at all. For example, how would you do such an awkward thing during backticks expansion.
I hope that we can get away by tweaking the DevPak plugin, though. I don't have that plugin installed here, and I never see a crash, so with some luck, we can replace all those wxYields, and it will fix your problem (one
wxYield at a time is not obnoxious).
First, however, it would be interesting to know whether deactivating plugins (particularly that one
EDIT: and code completion) really helps. If that doesn't change anything, then it isn't worthwile to look in that place