From 92eab475918b8ed4d9c5d8e362f38906ddd092ed Mon Sep 17 00:00:00 2001 From: Cory Petkovsek <632766+tinmanjuggernaut@users.noreply.github.com> Date: Thu, 11 Aug 2022 02:22:37 +0800 Subject: [PATCH] Fix free(RID) abuse by various classes (cherry picked from commit f7f112ab1f1b0c70f23f7ac643a108c4b4695914) --- scene/2d/particles_2d.cpp | 4 +++- scene/3d/gi_probe.cpp | 8 ++++++-- scene/3d/particles.cpp | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 79182cb2b86..6cdf5f8cd18 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -419,5 +419,7 @@ Particles2D::Particles2D() { } Particles2D::~Particles2D() { - VS::get_singleton()->free(particles); + if (particles.is_valid()) { + VS::get_singleton()->free(particles); + } } diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index f70d308cb34..df5f6de21b2 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -179,7 +179,9 @@ GIProbeData::GIProbeData() { } GIProbeData::~GIProbeData() { - VS::get_singleton()->free(probe); + if (probe.is_valid()) { + VS::get_singleton()->free(probe); + } } ////////////////////// @@ -527,5 +529,7 @@ GIProbe::GIProbe() { } GIProbe::~GIProbe() { - VS::get_singleton()->free(gi_probe); + if (gi_probe.is_valid()) { + VS::get_singleton()->free(gi_probe); + } } diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 4076aa27527..26c40e0677d 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -416,5 +416,7 @@ Particles::Particles() { } Particles::~Particles() { - VS::get_singleton()->free(particles); + if (particles.is_valid()) { + VS::get_singleton()->free(particles); + } }