From db91a73d5771e848d9056066c378b19774987842 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 14 Aug 2015 22:46:29 -0300 Subject: [PATCH] Trigger a Lua error if love.graphics.draw(canvas) is called while that canvas is the active one. This only catches a subset of the possible accidental read-while-writing situations that can happen when using Canvases, unfortunately. --- src/common/iOS.mm | 3 --- src/modules/graphics/opengl/Canvas.cpp | 9 +++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/iOS.mm b/src/common/iOS.mm index fb04631d5..e9eb8d1a3 100644 --- a/src/common/iOS.mm +++ b/src/common/iOS.mm @@ -323,9 +323,6 @@ std::string getExecutablePath() } } -static dispatch_queue_t queue = nil; -static dispatch_source_t timer = nil; - void vibrate() { @autoreleasepool diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index f3c735a16..1770a81e5 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -300,6 +300,12 @@ void Canvas::unloadVolatile() void Canvas::drawv(const Matrix4 &t, const Vertex *v) { + // FIXME: This doesn't handle cases where the Canvas is used as a texture + // in a SpriteBatch, Mesh, or ParticleSystem, or when the Canvas is used in + // a shader as a non-default texture. + if (Canvas::current == this) + throw love::Exception("Cannot draw a Canvas to itself."); + OpenGL::TempDebugGroup debuggroup("Canvas draw"); OpenGL::TempTransform transform(gl); @@ -327,8 +333,7 @@ void Canvas::drawq(Quad *quad, float x, float y, float angle, float sx, float sy { Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - const Vertex *v = quad->getVertices(); - drawv(t, v); + drawv(t, quad->getVertices()); } void Canvas::setFilter(const Texture::Filter &f)