Browse Source

Error if the coordinates given to Canvas:getPIxel are not within [0, dimensions).

Alex Szpakowski 11 years ago
parent
commit
1798115858
2 changed files with 5 additions and 2 deletions
  1. 2 2
      src/common/runtime.cpp
  2. 3 0
      src/modules/graphics/opengl/Canvas.cpp

+ 2 - 2
src/common/runtime.cpp

@@ -410,7 +410,7 @@ void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *obj
 		return luax_rawnewtype(L, name, flags, object);
 		return luax_rawnewtype(L, name, flags, object);
 	}
 	}
 
 
-	// Get the value of lovetypes[data] on the stack.
+	// Get the value of lovetypes[object] on the stack.
 	lua_pushlightuserdata(L, (void *) object);
 	lua_pushlightuserdata(L, (void *) object);
 	lua_gettable(L, -2);
 	lua_gettable(L, -2);
 
 
@@ -424,7 +424,7 @@ void luax_pushtype(lua_State *L, const char *name, bits flags, love::Object *obj
 		lua_pushlightuserdata(L, (void *) object);
 		lua_pushlightuserdata(L, (void *) object);
 		lua_pushvalue(L, -2);
 		lua_pushvalue(L, -2);
 
 
-		// lovetypes[data] = Proxy.
+		// lovetypes[object] = Proxy.
 		lua_settable(L, -4);
 		lua_settable(L, -4);
 	}
 	}
 
 

+ 3 - 0
src/modules/graphics/opengl/Canvas.cpp

@@ -891,6 +891,9 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
 
 
 void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
 void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
 {
 {
+	if (x < 0 || x >= width || y < 0 || y >= width)
+		throw love::Exception("Attempt to get out-of-range pixel (%d,%d)!", x, y);
+
 	resolveMSAA();
 	resolveMSAA();
 
 
 	// Our texture is attached to 'resolve_fbo' when we use MSAA.
 	// Our texture is attached to 'resolve_fbo' when we use MSAA.