瀏覽代碼

Fix crash when freeing GradientTexture and NoiseTexture

Haoyu Qiu 4 年之前
父節點
當前提交
37db8d6184
共有 3 個文件被更改,包括 6 次插入0 次删除
  1. 3 0
      core/templates/rid_owner.h
  2. 2 0
      modules/opensimplex/noise_texture.cpp
  3. 1 0
      scene/resources/texture.cpp

+ 3 - 0
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();
 				}

+ 2 - 0
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;
 	}

+ 1 - 0
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();
 }