From c0047023e6c1f3ca95f03371ddf9de716a466e97 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Mon, 6 Apr 2020 13:22:31 +0200 Subject: [PATCH] NoiseTexture: prevent race condition because of Ref::unref() (cherry picked from commit 1f0f0b8cea138ecda5e2cd36db50f76cd4bbab01) --- modules/opensimplex/noise_texture.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index aa1c8228139..b924f11e9a8 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -135,14 +135,19 @@ void NoiseTexture::_queue_update() { Ref NoiseTexture::_generate_texture() { - if (noise.is_null()) return Ref(); + // Prevent memdelete due to unref() on other thread. + Ref ref_noise = noise; + + if (ref_noise.is_null()) { + return Ref(); + } Ref 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) {