Browse Source

Made a bound check for sprite type indices.

David Piuva 5 years ago
parent
commit
486a693a42

+ 2 - 2
Source/SDK/sandbox/sprite/spriteAPI.cpp

@@ -676,8 +676,7 @@ SpriteWorld spriteWorld_create(OrthoSystem ortho, int shadowResolution) {
 
 
 void spriteWorld_addBackgroundSprite(SpriteWorld& world, const Sprite& sprite) {
 void spriteWorld_addBackgroundSprite(SpriteWorld& world, const Sprite& sprite) {
 	MUST_EXIST(world, spriteWorld_addBackgroundSprite);
 	MUST_EXIST(world, spriteWorld_addBackgroundSprite);
-	// TODO: Validate type index before looking up the bounding box, for easy debugging
-	// TODO: Replace sprite.location with a separate position argument, possibly constructing in place using the API
+	if (sprite.typeIndex < 0 || sprite.typeIndex >= types.length()) { throwError(U"Sprite type index ", sprite.typeIndex, " is out of bound!\n"); }
 	// Add the passive sprite to the octree
 	// Add the passive sprite to the octree
 	IVector3D origin = sprite.location;
 	IVector3D origin = sprite.location;
 	IVector3D minBound = origin + types[sprite.typeIndex].minBoundMini;
 	IVector3D minBound = origin + types[sprite.typeIndex].minBoundMini;
@@ -693,6 +692,7 @@ void spriteWorld_addBackgroundSprite(SpriteWorld& world, const Sprite& sprite) {
 
 
 void spriteWorld_addTemporarySprite(SpriteWorld& world, const Sprite& sprite) {
 void spriteWorld_addTemporarySprite(SpriteWorld& world, const Sprite& sprite) {
 	MUST_EXIST(world, spriteWorld_addTemporarySprite);
 	MUST_EXIST(world, spriteWorld_addTemporarySprite);
+	if (sprite.typeIndex < 0 || sprite.typeIndex >= types.length()) { throwError(U"Sprite type index ", sprite.typeIndex, " is out of bound!\n"); }
 	// Add the temporary sprite
 	// Add the temporary sprite
 	world->temporarySprites.push(sprite);
 	world->temporarySprites.push(sprite);
 }
 }

+ 2 - 2
Source/SDK/sandbox/sprite/spriteAPI.h

@@ -21,8 +21,8 @@ inline FVector3D parseFVector3D(const ReadableString& content) {
 	}
 	}
 }
 }
 
 
-// The sprite instance itself has a game-specific index to the sprite type
-// The caller should also have some kind of control over containing and rendering the items
+// A 2D image with depth and normal images for deferred light
+//   To be rendered into images in advance for maximum detail level
 struct Sprite {
 struct Sprite {
 public:
 public:
 	int typeIndex;
 	int typeIndex;