Skip to content

Commit

Permalink
#5231: Implement the shutdown handler, to ask for saving any pending …
Browse files Browse the repository at this point in the history
…changes to the map.

Fix crash at shutdown if the progress dialog is not cleaned up before the module it has been instantiated from is unloaded.
  • Loading branch information
codereader committed Jul 12, 2020
1 parent 80cfb35 commit bc6d7ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
4 changes: 4 additions & 0 deletions radiant/ui/mainframe/ScreenUpdateBlocker.cpp
Expand Up @@ -63,6 +63,10 @@ ScreenUpdateBlocker::~ScreenUpdateBlocker()

// Re-draw the scene to clear any artefacts in the buffer
GlobalMainFrame().updateAllWindows();

// Run one idle event loop, to allow wxWidgets to clean up the
// modal progress dialog window
wxTheApp->ProcessIdle();
}

void ScreenUpdateBlocker::pulse()
Expand Down
22 changes: 19 additions & 3 deletions radiantcore/map/Map.cpp
Expand Up @@ -65,7 +65,8 @@ namespace

Map::Map() :
_lastCopyMapName(""),
_saveInProgress(false)
_saveInProgress(false),
_shutdownListener(0)
{
_mapSaveTimer.Pause();
}
Expand Down Expand Up @@ -492,13 +493,13 @@ bool Map::askForSave(const std::string& title)
}

// Ask the user
ui::IDialogPtr msgBox = GlobalDialogManager().createMessageBox(
auto msgBox = GlobalDialogManager().createMessageBox(
title,
getSaveConfirmationText(),
ui::IDialog::MESSAGE_SAVECONFIRMATION
);

ui::IDialog::Result result = msgBox->run();
auto result = msgBox->run();

if (result == ui::IDialog::RESULT_CANCELLED)
{
Expand Down Expand Up @@ -872,10 +873,17 @@ void Map::initialiseModule(const ApplicationContext& ctx)
GlobalRadiant().signal_radiantShutdown().connect(
sigc::mem_fun(this, &Map::onRadiantShutdown)
);

_shutdownListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::Type::ApplicationShutdownRequest,
radiant::TypeListener<radiant::ApplicationShutdownRequest>(
sigc::mem_fun(this, &Map::handleShutdownRequest)));
}

void Map::shutdownModule()
{
GlobalRadiantCore().getMessageBus().removeListener(_shutdownListener);

_scaledModelExporter.shutdown();

GlobalSceneGraph().removeSceneObserver(this);
Expand All @@ -884,6 +892,14 @@ void Map::shutdownModule()
_mapPositionManager.reset();
}

void Map::handleShutdownRequest(radiant::ApplicationShutdownRequest& request)
{
if (!askForSave(_("Exit DarkRadiant")))
{
request.deny();
}
}

void Map::onRadiantShutdown()
{
freeMap();
Expand Down
19 changes: 12 additions & 7 deletions radiantcore/map/Map.h
Expand Up @@ -13,6 +13,7 @@
#include "model/export/ScaledModelExporter.h"
#include "model/export/ModelScalePreserver.h"
#include "MapPositionManager.h"
#include "messages/ApplicationShutdownRequest.h"

#include <sigc++/signal.h>
#include <wx/stopwatch.h>
Expand Down Expand Up @@ -55,6 +56,8 @@ class Map :

MapEventSignal _mapEvent;

std::size_t _shutdownListener;

private:
std::string getSaveConfirmationText() const;

Expand Down Expand Up @@ -165,13 +168,6 @@ class Map :
*/
MapFormatPtr getFormat();

/** greebo: Asks the user if the current changes should be saved.
*
* @returns: true, if the user gave clearance (map was saved, had no
* changes to be saved, etc.), false, if the user hit "cancel".
*/
bool askForSave(const std::string& title);

/** greebo: Focus the XYViews and the Camera to the given point/angle.
*/
static void focusViews(const Vector3& point, const Vector3& angles);
Expand Down Expand Up @@ -199,6 +195,15 @@ class Map :
static void saveSelectedAsPrefab(const cmd::ArgumentList& args);

private:
/**
* greebo: Asks the user if the current changes should be saved.
*
* @returns: true, if the user gave clearance (map was saved, had no
* changes to be saved, etc.), false, if the user hit "cancel".
*/
bool askForSave(const std::string& title);

void handleShutdownRequest(radiant::ApplicationShutdownRequest& request);

/** greebo: Loads a prefab and translates it to the given target coordinates
*/
Expand Down

0 comments on commit bc6d7ad

Please sign in to comment.