bugfix: swallow exceptions in save_blocker dtor
See code comments for more discussion.
This commit is contained in:
parent
23ca125d4e
commit
675c8a95f7
2 changed files with 21 additions and 0 deletions
|
@ -13,6 +13,8 @@
|
|||
*/
|
||||
|
||||
#include "save_blocker.hpp"
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
play_controller* save_blocker::controller_ = NULL;
|
||||
void (play_controller::*save_blocker::callback_)() = NULL;
|
||||
|
@ -23,12 +25,16 @@ save_blocker::save_blocker() {
|
|||
}
|
||||
|
||||
save_blocker::~save_blocker() {
|
||||
try {
|
||||
unblock();
|
||||
if(controller_ && callback_) {
|
||||
(controller_->*callback_)();
|
||||
controller_ = NULL;
|
||||
callback_ = NULL;
|
||||
}
|
||||
} catch (std::exception & e) {
|
||||
std::cerr << "Save blocker dtor swallowing an exception: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void save_blocker::on_unblock(play_controller* controller, void (play_controller::*callback)()) {
|
||||
|
|
|
@ -27,6 +27,21 @@ class play_controller;
|
|||
* then be reinvoked from this class's destructor. If multiple save attempts
|
||||
* are performed, only the last will be carried out.
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is broken and you probably shouldn't use it. Calling a save
|
||||
* game dialog from the destructor of a class is a bad idea, because those
|
||||
* functions throw exceptions. For example if the user decides to quit the game,
|
||||
* or there is a filesystem erorr. If the destructor throws exceptions, it will
|
||||
* cause memory leaks and crashes.
|
||||
* http://wiki.wesnoth.org/CodingStandards#Destructors_must_not_throw_exceptions
|
||||
*
|
||||
* As a temporary fix the destructor has been changed to swallow all exceptions.
|
||||
* However this means that if the user attempts to quit the game from the savegame
|
||||
* dialog, or any filesystem error occurs, it will be suppressed instead of being
|
||||
* handled normally. So you should avoid using this class and it may be removed.
|
||||
*/
|
||||
|
||||
class save_blocker {
|
||||
public:
|
||||
save_blocker();
|
||||
|
|
Loading…
Add table
Reference in a new issue