Explorar o código

NoiseTexture: prevent race condition because of Ref::unref()

(cherry picked from commit 1f0f0b8cea138ecda5e2cd36db50f76cd4bbab01)
lupoDharkael %!s(int64=5) %!d(string=hai) anos
pai
achega
c0047023e6
Modificáronse 1 ficheiros con 8 adicións e 3 borrados
  1. 8 3
      modules/opensimplex/noise_texture.cpp

+ 8 - 3
modules/opensimplex/noise_texture.cpp

@@ -135,14 +135,19 @@ void NoiseTexture::_queue_update() {
 
 Ref<Image> NoiseTexture::_generate_texture() {
 
-	if (noise.is_null()) return Ref<Image>();
+	// Prevent memdelete due to unref() on other thread.
+	Ref<OpenSimplexNoise> ref_noise = noise;
+
+	if (ref_noise.is_null()) {
+		return Ref<Image>();
+	}
 
 	Ref<Image> image;
 
 	if (seamless) {
-		image = noise->get_seamless_image(size.x);
+		image = ref_noise->get_seamless_image(size.x);
 	} else {
-		image = noise->get_image(size.x, size.y);
+		image = ref_noise->get_image(size.x, size.y);
 	}
 
 	if (as_normalmap) {