diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 22:05:16 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 22:05:16 +0100 |
commit | ff7390073ad42b9584aa2c509669867edab8c2f6 (patch) | |
tree | 9d6674ba6e7fcaf9b56516172195bab52dbe2dfe | |
parent | 80ed1262bd654fe2de30389f97a985b5f2c1d783 (diff) |
fix List::remove
-rw-r--r-- | backend/List.hpp | 11 | ||||
-rw-r--r-- | frontend/cmd/get.cpp | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/backend/List.hpp b/backend/List.hpp index f4dce23..25e7a56 100644 --- a/backend/List.hpp +++ b/backend/List.hpp @@ -28,8 +28,15 @@ void List<T>::remove(const T & target) { } if (link == nullptr) return; // target not in list - if (link->next != nullptr) link->next->prev = link->prev; - if (link->prev != nullptr) link->prev->next = link->next; + if (link->next == nullptr) + this->head = link->prev; + else + link->next->prev = link->prev; + if (link->prev == nullptr) + this->tail = link->next; + else + link->prev->next = link->next; + delete link; this->length--; } diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp index 8aa2d75..2a35657 100644 --- a/frontend/cmd/get.cpp +++ b/frontend/cmd/get.cpp @@ -12,13 +12,13 @@ FollowupAction Player::cmd_get(string & target_name) { for (Object * object : this->location.get_visible_objects()) { if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue; target = unique_ptr<Object>(object); - this->location.remove_visible_object(object); break; } if (target == nullptr) { lprtf("Object \"%s\" niet gevonden\n", target_name.c_str()); return FollowupAction::NONE; } + this->location.remove_visible_object(target.get()); // gold objects are collected and (implicitly) destroyed GoldObject * gold = dynamic_cast<GoldObject *>(target.get()); |