summaryrefslogtreecommitdiff
path: root/core/image.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-07-03 13:52:10 +0200
committerGitHub <noreply@github.com>2020-07-03 13:52:10 +0200
commit772f693e5b8b5912d422e8effb8d6a72260edcfc (patch)
treec3821da6824e3fe024659c13cec0d9fd12e55877 /core/image.cpp
parent8ff99d2a8e75bb99ec8ba99fb0774e221d4d096a (diff)
parentb5488def4750665b8ca68b6cbdfdd824895fd38f (diff)
Merge pull request #40083 from akien-mga/img-better-create-error
Image: Improve error messages for invalid creation size
Diffstat (limited to 'core/image.cpp')
-rw-r--r--core/image.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/core/image.cpp b/core/image.cpp
index e2b184fcde..e2f353698f 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1895,8 +1895,10 @@ Vector<uint8_t> Image::get_data() const {
}
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
- ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
- ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
+ ERR_FAIL_COND_MSG(p_width <= 0, "Image width must be greater than 0.");
+ ERR_FAIL_COND_MSG(p_height <= 0, "Image height must be greater than 0.");
+ ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + ".");
+ ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
int mm = 0;
@@ -1915,8 +1917,10 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
}
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
- ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
- ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
+ ERR_FAIL_COND_MSG(p_width <= 0, "Image width must be greater than 0.");
+ ERR_FAIL_COND_MSG(p_height <= 0, "Image height must be greater than 0.");
+ ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + ".");
+ ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
int mm;