From 0fc17ec277a2e01b083e9fce096722fe522e13a7 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 20 Apr 2021 11:41:19 -0700 Subject: [PATCH] Fix only removing duplicate script names from script name list If there were two scripts with the same name, removing one of them would only remove the other script from the script name list, and not also remove the contents of said script - leading to a desync in state, which is probably bad. Fixing this isn't as simple as removing the break statement - I either also have to decrement the loop variable when removing the script, or iterate backwards. I chose to iterate backwards here because it relocates less memory than iterating forwards. --- desktop_version/src/editor.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 79b22c4e..05f17b52 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -452,15 +452,14 @@ void editorclass::addhooktoscript(std::string t) void editorclass::removehookfromscript(std::string t) { - //Find hook t in the scriptclass, then removes it (and any other code with it) - for (size_t i = 0; i < script.customscripts.size(); i++) + /* Find hook t in the scriptclass, then removes it (and any other code with it) + * When this loop reaches the end, it wraps to SIZE_MAX; SIZE_MAX + 1 is 0 */ + size_t i; + for (i = script.customscripts.size() - 1; i + 1 > 0; --i) { - Script& script_ = script.customscripts[i]; - - if (script_.name == t) + if (script.customscripts[i].name == t) { script.customscripts.erase(script.customscripts.begin() + i); - break; } } }