Browse Source

love.graphics.copyBuffer: slightly more robust error handling.

Sasha Szpakowski 2 years ago
parent
commit
416abdbc59
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/modules/graphics/Graphics.cpp

+ 9 - 0
src/modules/graphics/Graphics.cpp

@@ -1370,6 +1370,9 @@ void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, siz
 	if (dest->isImmutable())
 	if (dest->isImmutable())
 		throw love::Exception("Cannot copy to an immutable buffer.");
 		throw love::Exception("Cannot copy to an immutable buffer.");
 
 
+	if (sourceoffset % 4 != 0 || destoffset % 4 != 0 || size % 4 != 0)
+		throw love::Exception("Buffer copy source offset, destination offset, and size parameters must be multiples of 4 bytes.");
+
 	source->copyTo(dest, sourceoffset, destoffset, size);
 	source->copyTo(dest, sourceoffset, destoffset, size);
 }
 }
 
 
@@ -1456,6 +1459,9 @@ void Graphics::copyTextureToBuffer(Texture *source, Buffer *dest, int slice, int
 
 
 	Range destrange(destoffset, size);
 	Range destrange(destoffset, size);
 
 
+	if (destoffset % 4 != 0 || size % 4 != 0)
+		throw love::Exception("Buffer copy destination offset and computed byte size must be multiples of 4 bytes.");
+
 	if (destrange.getMax() >= dest->getSize())
 	if (destrange.getMax() >= dest->getSize())
 		throw love::Exception("Buffer copy destination offset and width/height doesn't fit within the destination Buffer.");
 		throw love::Exception("Buffer copy destination offset and width/height doesn't fit within the destination Buffer.");
 
 
@@ -1536,6 +1542,9 @@ void Graphics::copyBufferToTexture(Buffer *source, Texture *dest, size_t sourceo
 
 
 	Range sourcerange(sourceoffset, size);
 	Range sourcerange(sourceoffset, size);
 
 
+	if (sourceoffset % 4 != 0 || size % 4 != 0)
+		throw love::Exception("Buffer copy source offset and computed byte size must be multiples of 4 bytes.");
+
 	if (sourcerange.getMax() >= source->getSize())
 	if (sourcerange.getMax() >= source->getSize())
 		throw love::Exception("Buffer copy source offset and width/height doesn't fit within the source Buffer.");
 		throw love::Exception("Buffer copy source offset and width/height doesn't fit within the source Buffer.");