From f8c6c66d157adc18fa87cfd0ddd8a692c4f75846 Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Sun, 12 Jan 2025 15:27:25 +0800 Subject: [PATCH] Fix memory corruption with shared wheel and headlight, see #5240 --- src/karts/kart_model.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 933cd13a1c4..ccc4632ad1f 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -267,7 +267,8 @@ KartModel::~KartModel() if(m_is_master && m_wheel_model[i]) { irr_driver->dropAllTextures(m_wheel_model[i]); - irr_driver->removeMeshFromCache(m_wheel_model[i]); + if (m_wheel_model[i]->getReferenceCount() == 1) + irr_driver->removeMeshFromCache(m_wheel_model[i]); } }