diff options
author | frosch <frosch@openttd.org> | 2015-04-27 19:28:22 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2015-04-27 19:28:22 +0000 |
commit | eb25d9e275a8fe165f52f669696d5be15efd748d (patch) | |
tree | 3be70e538b5dcb6bc75514532f13d41e9a39113b | |
parent | 2ea4466230234974d5e822bbb824d2deec3cfaa3 (diff) | |
download | openttd-eb25d9e275a8fe165f52f669696d5be15efd748d.tar.xz |
(svn r27258) -Fix [FS#6287]: ScriptList::RemoveList failed to remove a list from itself.
-rw-r--r-- | src/script/api/script_list.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index 3ffca3598..bdbc1209b 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -556,6 +556,8 @@ void ScriptList::Sort(SorterType sorter, bool ascending) void ScriptList::AddList(ScriptList *list) { + if (list == this) return; + ScriptListMap *list_items = &list->items; for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { this->AddItem((*iter).first); @@ -565,6 +567,8 @@ void ScriptList::AddList(ScriptList *list) void ScriptList::SwapList(ScriptList *list) { + if (list == this) return; + this->items.swap(list->items); this->buckets.swap(list->buckets); Swap(this->sorter, list->sorter); @@ -694,9 +698,13 @@ void ScriptList::RemoveList(ScriptList *list) { this->modifications++; - ScriptListMap *list_items = &list->items; - for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { - this->RemoveItem((*iter).first); + if (list == this) { + Clear(); + } else { + ScriptListMap *list_items = &list->items; + for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { + this->RemoveItem((*iter).first); + } } } @@ -756,14 +764,12 @@ void ScriptList::KeepBottom(int32 count) void ScriptList::KeepList(ScriptList *list) { + if (list == this) return; + this->modifications++; ScriptList tmp; - for (ScriptListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { - tmp.AddItem((*iter).first); - tmp.SetValue((*iter).first, (*iter).second); - } - + tmp.AddList(this); tmp.RemoveList(list); this->RemoveList(&tmp); } |