Skip to content

Commit

Permalink
#5527: Move static wx initialisation code to RadiantApp, add the corr…
Browse files Browse the repository at this point in the history
…esponding tear down calls rather than leaving the app without cleanup.
  • Loading branch information
codereader committed Feb 7, 2021
1 parent 7a7207f commit 11cd8c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
39 changes: 30 additions & 9 deletions radiant/RadiantApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wx/wxprec.h>
#include <wx/event.h>
#include <wx/cmdline.h>
#include <wx/xrc/xmlres.h>
#include <sigc++/functors/mem_fun.h>

#ifndef __linux__
Expand Down Expand Up @@ -60,10 +61,6 @@ bool RadiantApp::OnInit()
g_log_set_writer_func(log_black_hole, nullptr, nullptr);
#endif

// Stop wx's unhelpful debug messages about missing keyboard accel
// strings from cluttering up the console
wxLog::SetLogLevel(wxLOG_Warning);

// Initialise the context (application path / settings path, is
// OS-specific)
_context.initialise(wxApp::argc, wxApp::argv);
Expand Down Expand Up @@ -102,10 +99,8 @@ bool RadiantApp::OnInit()
setlocale(LC_NUMERIC, "C");
setlocale(LC_TIME, "C");

wxInitAllImageHandlers();

// Register the local art provider
_bitmapArtProvider = std::make_unique<wxutil::LocalBitmapArtProvider>(_context.getBitmapsPath());
// Set up art provider, logging, XRC file handlers
initWxWidgets();

// Register to the start up signal
Bind(EV_RadiantStartup, &RadiantApp::onStartupEvent, this);
Expand All @@ -115,6 +110,32 @@ bool RadiantApp::OnInit()
return true;
}

void RadiantApp::initWxWidgets()
{
// Stop wx's unhelpful debug messages about missing keyboard accel
// strings from cluttering up the console
wxLog::SetLogLevel(wxLOG_Warning);

wxFileSystem::AddHandler(new wxLocalFSHandler);
wxXmlResource::Get()->InitAllHandlers();

// Our XRC resource files are stored in the ui/ folder.
wxXmlResource::Get()->Load(_context.getRuntimeDataPath() + "ui/*.xrc");

wxInitAllImageHandlers();

// Register the local art provider
_bitmapArtProvider = std::make_unique<wxutil::LocalBitmapArtProvider>(_context.getBitmapsPath());
}

void RadiantApp::cleanupWxWidgets()
{
_bitmapArtProvider.reset();
wxImage::CleanUpHandlers();
wxXmlResource::Get()->ClearHandlers();
wxFileSystem::CleanUpHandlers();
}

int RadiantApp::OnExit()
{
// Issue a shutdown() call to all the modules
Expand All @@ -128,7 +149,7 @@ int RadiantApp::OnExit()

_coreModule.reset();

_bitmapArtProvider.reset();
cleanupWxWidgets();

return wxApp::OnExit();
}
Expand Down
2 changes: 2 additions & 0 deletions radiant/RadiantApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ class RadiantApp :
private:
void onStartupEvent(wxCommandEvent& ev);
void onModulesUnloading();
void initWxWidgets();
void cleanupWxWidgets();
};
10 changes: 0 additions & 10 deletions radiant/uimanager/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "imainframe.h"
#include "GroupDialog.h"

#include <wx/xrc/xmlres.h>

namespace ui
{

Expand All @@ -22,8 +20,6 @@ IGroupDialog& UIManager::getGroupDialog() {
void UIManager::clear()
{
_dialogManager.reset();

wxFileSystem::CleanUpHandlers();
}

const std::string& UIManager::getName() const
Expand Down Expand Up @@ -53,12 +49,6 @@ void UIManager::initialiseModule(const IApplicationContext& ctx)
GlobalMainFrame().signal_MainFrameShuttingDown().connect(
sigc::mem_fun(this, &UIManager::clear)
);

wxFileSystem::AddHandler(new wxLocalFSHandler);
wxXmlResource::Get()->InitAllHandlers();

std::string fullPath = ctx.getRuntimeDataPath() + "ui/";
wxXmlResource::Get()->Load(fullPath + "*.xrc");
}

module::StaticModule<UIManager> uiManagerModule;
Expand Down

0 comments on commit 11cd8c2

Please sign in to comment.