mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-03 15:39:46 +01: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:
parent
779a48dbb4
commit
0fc17ec277
1 changed files with 5 additions and 6 deletions
|
@ -452,15 +452,14 @@ void editorclass::addhooktoscript(std::string t)
|
||||||
|
|
||||||
void editorclass::removehookfromscript(std::string t)
|
void editorclass::removehookfromscript(std::string t)
|
||||||
{
|
{
|
||||||
//Find hook t in the scriptclass, then removes it (and any other code with it)
|
/* 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++)
|
* 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.customscripts[i].name == t)
|
||||||
|
|
||||||
if (script_.name == t)
|
|
||||||
{
|
{
|
||||||
script.customscripts.erase(script.customscripts.begin() + i);
|
script.customscripts.erase(script.customscripts.begin() + i);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue