Fix love.event.quit causing crashes and other bad behaviour if a Canvas is active. Resolves issue #1395.

This commit is contained in:
Alex Szpakowski
2018-04-07 12:43:00 -03:00
parent 7b91ab915c
commit bb228cab0c
3 changed files with 20 additions and 10 deletions
+8 -5
View File
@@ -271,11 +271,14 @@ bool Canvas::loadVolatile()
void Canvas::unloadVolatile()
{
// This is a bit ugly, but we need some way to destroy the cached FBO
// when this Canvas' texture is destroyed.
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->cleanupCanvas(this);
if (fbo != 0 || renderbuffer != 0 || texture != 0)
{
// This is a bit ugly, but we need some way to destroy the cached FBO
// when this Canvas' texture is destroyed.
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->cleanupCanvas(this);
}
if (fbo != 0)
gl.deleteFramebuffer(fbo);
+10 -5
View File
@@ -77,7 +77,7 @@ Window::Window()
Window::~Window()
{
close();
close(false);
graphics.set(nullptr);
@@ -413,7 +413,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
graphics.set(Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS));
if (graphics.get() && graphics->isCanvasActive())
throw love::Exception("setMode cannot be called while a Canvas is active in love.graphics.");
throw love::Exception("love.window.setMode cannot be called while a Canvas is active in love.graphics.");
WindowSettings f;
@@ -640,11 +640,16 @@ void Window::getWindow(int &width, int &height, WindowSettings &newsettings)
}
void Window::close()
{
close(true);
}
void Window::close(bool allowExceptions)
{
if (graphics.get())
{
if (graphics->isCanvasActive())
throw love::Exception("close cannot be called while a Canvas is active in love.graphics.");
if (allowExceptions && graphics->isCanvasActive())
throw love::Exception("love.window.close cannot be called while a Canvas is active in love.graphics.");
graphics->unSetMode();
}
@@ -674,7 +679,7 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
return false;
if (graphics.get() && graphics->isCanvasActive())
throw love::Exception("setFullscreen cannot be called while a Canvas is active in love.graphics.");
throw love::Exception("love.window.setFullscreen cannot be called while a Canvas is active in love.graphics.");
WindowSettings newsettings = settings;
newsettings.fullscreen = fullscreen;
+2
View File
@@ -121,6 +121,8 @@ public:
private:
void close(bool allowExceptions);
struct ContextAttribs
{
int versionMajor;