Issue tracked down. It was a conflict between SDL2 initializeing and wxWidgets initializing. Apparently only happens on OS X with wxWidgets 3.x.
Best solution IMO is to initialize SDL Video only when we need it to detect resolutions, rather than trying to initialize it at wxL startup. wxL works correctly on OS X when this change is made.
I do not recommend using SDL_Init() because according to the
SDL Wiki it initializes subsystems that we never use like File I/O and Threads. IMO it’s best to just initialize the subsystems we actually need.
If we make this change, then we need to decide when to shut the SDL video subsystem down. Two options:
- right after we’re done detecting resolutions, similar to how SDL joystick subsystem is initialized right before detecting joysticks and shut down right after detecting joysticks. It does mean we’d be repeatedly initializing and shutting down the SDL video subsystem as wxL runs, dunno if that’s an issue. We already do just that with the SDL joystick subsystem.
- when shutting down wxL, something like the following in wxLauncher::OnExit():
#if HAS_SDL == 1
Uint32 initedSubsystems = SDL_WasInit(0);
if (initedSubsystems) {
SDL_QuitSubSystem(initedSubsystems);
}
#endif
We could shut down the SDL joystick subsystem the same way (that is, at wxL exit) rather than repeatedly initializing/quitting it.
On a related note, why are we still using Win32 API to detect resolutions on Windows? If we’re using SDL everywhere then why not use SDL on all platforms for resolution detection?
Also apparently the SDL joystick subsystem was being initialized without checking the return value from SDL_InitSubsystem(), so we weren’t checking if the init actually succeeded.
Might as well fix that too while tinkering with the SDL code.
Here is a patch that initializes SDL video before detecting resolutions and shuts it down right after detecting resolutions (that is, option #1 mentioned above). Since SDL is no longer being initialized at wxL startup, we can remove the custom main() function, so I did that as well.Tested on OS X, needs testing on Windows/Linux. I’ll try to get around to it if someone else doesn’t first.EDIT 3: Patch doesn't work on Linux, see
this post for updated patch.
One known issue: looks like the top bar menu on OS X for wxL is empty, meaning no About dialog. I don't feel like this is worth trying to fix and is probably something in wxWidgets anyway.
While testing on OS X, I got a couple crashes on wxL shutdown. Here’s a patch to plug those holes:
diff --git a/code/apis/ProfileManager.h b/code/apis/ProfileManager.h
index 0990057..d567be2 100644
--- a/code/apis/ProfileManager.h
+++ b/code/apis/ProfileManager.h
@@ -55,6 +55,7 @@ public:
};
static bool Initialize(Flags flags = None);
static bool DeInitialize();
+ static bool IsInitialized() { return isInitialized; }
static ProMan* GetProfileManager();
virtual ~ProMan();
diff --git a/code/apis/TCManager.cpp b/code/apis/TCManager.cpp
index 6afde00..078e7de 100644
--- a/code/apis/TCManager.cpp
+++ b/code/apis/TCManager.cpp
@@ -35,7 +35,9 @@ TCManager::TCManager() {
}
/** Destructor. Static class does nothing. */
TCManager::~TCManager() {
- ProMan::GetProfileManager()->RemoveEventHandler(this);
+ if (ProMan::IsInitialized()) {
+ ProMan::GetProfileManager()->RemoveEventHandler(this);
+ }
}
TCManager* TCManager::manager = NULL;
diff --git a/code/controls/ModList.cpp b/code/controls/ModList.cpp
index 3195ab8..c290cb5 100644
--- a/code/controls/ModList.cpp
+++ b/code/controls/ModList.cpp
@@ -604,7 +604,9 @@ ModList::ModList(wxWindow *parent, wxSize& size, wxString tcPath)
/** the dtor. Cleans up stuff. */
ModList::~ModList() {
- SkinSystem::UnRegisterTCSkinChanged(this);
+ if (SkinSystem::IsInitialized()) {
+ SkinSystem::UnRegisterTCSkinChanged(this);
+ }
if ( this->configFiles != NULL ) {
delete this->configFiles;
Once this is sorted out we can work on getting CMakeLists.txt updated to support OS X again, and I can also update the ReadMe with current build instructions for OS X.
Randomly, I've noticed that wxL does not show it's own version anywhere as far as I can tell. This might be a useful little piece of info to make visible somewhere.
I think it's printed to the log but yeah it'd probably be good to show it somewhere in the GUI. A cross-platform About dialog would be a considerable amount of work. Maybe we could stick it in the default window title? As in "wxLauncher 0.12.0-rc2 for the FreeSpace 2 Source Code PRoject". Not sure offhand how hard that would be to do, probably not very though. EDIT: Or maybe display it prominently in the Help manual? Displaying it in the default window title isn't foolproof because TCs (and maybe also mods, I forget) can change the window title through the skin system.
EDIT 2: While we're fixing stuff in wxL, could also fix that annoying bug in displaying build versions where certain commit hashes don't appear in the GUI. I have a patch for it somewhere in the nightly builds forum, would have to dig it up.