1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-18 10:38:31 +02:00

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.
This commit is contained in:
Misa 2021-04-20 11:41:19 -07:00 committed by Ethan Lee
parent 779a48dbb4
commit 0fc17ec277

View File

@ -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;
}
}
}