Fix crash when resizing a sprite and there is not enough memory

This patch fixes crashes in background jobs that generate any kind of
exception.
This commit is contained in:
David Capello 2016-07-22 20:46:29 -03:00
parent 2893f98fbd
commit 4ef9626689
3 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -152,7 +152,10 @@ void Console::printf(const char* format, ...)
void Console::showException(const std::exception& e)
{
Console console;
console.printf("A problem has occurred.\n\nDetails:\n%s\n", e.what());
if (typeid(e) == typeid(std::bad_alloc))
console.printf("There is not enough memory to complete the action.");
else
console.printf("A problem has occurred.\n\nDetails:\n%s\n", e.what());
}
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -12,6 +12,7 @@
#include "app/job.h"
#include "app/app.h"
#include "app/console.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include "base/thread.h"
@ -70,6 +71,18 @@ void Job::startJob()
if (!m_done_flag)
m_canceled_flag = true;
}
// In case of error, take the "cancel" path (i.e. it's like the
// user canceled the operation).
if (m_error) {
m_canceled_flag = true;
try {
std::rethrow_exception(m_error);
}
catch (const std::exception& ex) {
Console::showException(ex);
}
}
}
}
@ -122,7 +135,7 @@ void Job::thread_proc(Job* self)
self->onJob();
}
catch (...) {
// TODO handle this exception
self->m_error = std::current_exception();
}
self->done();
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -13,6 +13,8 @@
#include "ui/alert.h"
#include "ui/timer.h"
#include <exception>
namespace base {
class thread;
class mutex;
@ -67,6 +69,7 @@ namespace app {
double m_last_progress;
bool m_done_flag;
bool m_canceled_flag;
std::exception_ptr m_error;
// these methods are privated and not defined
Job();