From 8ddac86fd214c90b916f49029ff73b78a8d3f79b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 29 Jan 2018 19:48:29 -0800 Subject: [PATCH 1/2] Don't CleanUpModules when reinitializing. --- src/wxpy_api.sip | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wxpy_api.sip b/src/wxpy_api.sip index cd8089e7..c754b1c4 100644 --- a/src/wxpy_api.sip +++ b/src/wxpy_api.sip @@ -549,10 +549,22 @@ inline PyObject* i_wxPyMethod_Self(PyObject* method) { void i_wxPyReinitializeModules() { if (i_wxPyCheckForApp(false)) { - wxModule::CleanUpModules(); + // NOTE: We are intentionally NOT calling wxModule::CleanUpModules + // here because that could clear some things that will not be reset + // when used again, leading to crashes. For example, in + // wxMSWDCImpl::DoGradientFillLinear it is saving a pointer to an API + // function in a dyn-loaded DLL. When modules are cleaned up then that + // DLL will be unloaded, leaving a dangling function pointer. We'll + // likely end up with multiple instances of some things, but that is + // better than the alternaive currently. + //wxModule::CleanUpModules(); + wxModule::RegisterModules(); wxModule::InitializeModules(); - wxInitAllImageHandlers(); + + // And since we're not calling CleanUpModules there is no longer any + // need to re-init the image handlers. + //wxInitAllImageHandlers(); } } From ae563770e280f68d6ab08e4906d999763feb0e8c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 29 Jan 2018 19:55:52 -0800 Subject: [PATCH 2/2] Add changelog --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1c6291bb..5d48bd6d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -215,6 +215,9 @@ Changes in this release include the following: can be handy in the rare cases where something holds on to a DC for too long, perhaps unintentionally. (#680) +* Fixed crash due to too aggressive management of wxModules when we load + subordinate extensions that have their own wxModules (wx.html, wx.adv, etc.) + (#688)