diff options
-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()); |