summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2021-06-14 12:29:41 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2021-06-14 12:32:19 +0800
commit37db8d61845f1bf22d50939268aa8baa2663d06b (patch)
tree2ea1b82bb6f927d4fd01a006a70f27b6f971a092
parent12e0f10c74e9619262f1edcfdc1840432ada0565 (diff)
downloadredot-engine-37db8d61845f1bf22d50939268aa8baa2663d06b.tar.gz
Fix crash when freeing GradientTexture and NoiseTexture
-rw-r--r--core/templates/rid_owner.h3
-rw-r--r--modules/opensimplex/noise_texture.cpp2
-rw-r--r--scene/resources/texture.cpp1
3 files changed, 6 insertions, 0 deletions
diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h
index c4aa93c394..31278b71bd 100644
--- a/core/templates/rid_owner.h
+++ b/core/templates/rid_owner.h
@@ -351,6 +351,9 @@ public:
for (size_t i = 0; i < max_alloc; i++) {
uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk];
+ if (validator & 0x80000000) {
+ continue; //uninitialized
+ }
if (validator != 0xFFFFFFFF) {
chunks[i / elements_in_chunk][i % elements_in_chunk].~T();
}
diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp
index 9e0155da94..66c52ffbf9 100644
--- a/modules/opensimplex/noise_texture.cpp
+++ b/modules/opensimplex/noise_texture.cpp
@@ -187,6 +187,7 @@ Ref<OpenSimplexNoise> NoiseTexture::get_noise() {
}
void NoiseTexture::set_width(int p_width) {
+ ERR_FAIL_COND(p_width <= 0);
if (p_width == size.x) {
return;
}
@@ -195,6 +196,7 @@ void NoiseTexture::set_width(int p_width) {
}
void NoiseTexture::set_height(int p_height) {
+ ERR_FAIL_COND(p_height <= 0);
if (p_height == size.y) {
return;
}
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 064563d4b5..938cd9b54f 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1595,6 +1595,7 @@ void GradientTexture::_update() {
}
void GradientTexture::set_width(int p_width) {
+ ERR_FAIL_COND(p_width <= 0);
width = p_width;
_queue_update();
}