- // Cleanup user-defined modules
- wxModuleList::compatibility_iterator node;
- for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
+ wxModuleList initializedModules;
+
+ for ( wxModuleList::compatibility_iterator node = m_modules.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ wxModule *module = node->GetData();
+
+ // the module could have been already initialized as dependency of
+ // another one
+ if ( module->m_state == State_Registered )
+ {
+ if ( !DoInitializeModule( module, initializedModules ) )
+ {
+ // failed to initialize all modules, so clean up the already
+ // initialized ones
+ DoCleanUpModules(initializedModules);
+
+ return false;
+ }
+ }
+ }
+
+ // remember the real initialisation order
+ m_modules = initializedModules;
+
+ return true;
+}
+
+// Clean up all currently initialized modules
+void wxModule::DoCleanUpModules(const wxModuleList& modules)
+{
+ // cleanup user-defined modules in the reverse order compared to their
+ // initialization -- this ensures that dependencies are respected
+ for ( wxModuleList::compatibility_iterator node = modules.GetLast();
+ node;
+ node = node->GetPrevious() )