From a59ff847bcc064aa78318d5c7161420595abe159 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:31:28 +1100 Subject: [PATCH] Fix UB when a unique effect script adds another unique effect during initialization --- .../interface/windowconfig/charselection.config.patch | 4 ++-- source/game/StarStatusController.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/opensb/interface/windowconfig/charselection.config.patch b/assets/opensb/interface/windowconfig/charselection.config.patch index 731a075..c904b44 100644 --- a/assets/opensb/interface/windowconfig/charselection.config.patch +++ b/assets/opensb/interface/windowconfig/charselection.config.patch @@ -1,4 +1,4 @@ -[{"op":"merge", "path":"", "value": { +{ "createCharButton" : { "type" : "button", "base" : "/interface/title/createcharacter.png", @@ -6,4 +6,4 @@ "position" : [23, 241], "pressedOffset" : [0, 0] } -}}] +} diff --git a/source/game/StarStatusController.cpp b/source/game/StarStatusController.cpp index 325fc17..26c83d0 100644 --- a/source/game/StarStatusController.cpp +++ b/source/game/StarStatusController.cpp @@ -410,8 +410,9 @@ void StatusController::init(Entity* parentEntity, ActorMovementController* movem if (m_parentEntity->isMaster()) { initPrimaryScript(); - for (auto& p : m_uniqueEffects) - initUniqueEffectScript(p.second); + for (auto& p : m_uniqueEffects.keys()) + if (auto effect = m_uniqueEffects.ptr(p)) + initUniqueEffectScript(*effect); } m_environmentStatusEffectUpdateTimer.reset(); @@ -421,8 +422,9 @@ void StatusController::uninit() { m_parentEntity = nullptr; m_movementController = nullptr; - for (auto& p : m_uniqueEffects) - uninitUniqueEffectScript(p.second); + for (auto& p : m_uniqueEffects.keys()) + if (auto effect = m_uniqueEffects.ptr(p)) + uninitUniqueEffectScript(*effect); uninitPrimaryScript(); m_recentHitsGiven.reset();