From: Daniel Karbach Date: Mon, 26 Oct 2015 09:05:08 +0000 (+0100) Subject: remove self on player controller destruct X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=916cba3b7b9dea6459febb90d24565cf4c0a8b2a;p=blank.git remove self on player controller destruct fixes segfault when the world is being simulated after the player exits (like e.g. on a server :>) --- diff --git a/doc/todo b/doc/todo index 707491b..704487f 100644 --- a/doc/todo +++ b/doc/todo @@ -116,7 +116,3 @@ spawning sprite/particle system these could help make the world seem more alive - -server - - fix segfault at disconnect diff --git a/src/ui/PlayerController.hpp b/src/ui/PlayerController.hpp index 9d54c29..9cf0bca 100644 --- a/src/ui/PlayerController.hpp +++ b/src/ui/PlayerController.hpp @@ -18,6 +18,7 @@ class PlayerController public: PlayerController(World &, Player &); + ~PlayerController(); World &GetWorld() noexcept { return world; } const World &GetWorld() const noexcept { return world; } diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index dd113ca..6a2e2ee 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -43,6 +43,12 @@ PlayerController::PlayerController(World &world, Player &player) player.GetEntity().SetController(*this); } +PlayerController::~PlayerController() { + if (&player.GetEntity().GetController() == this) { + player.GetEntity().UnsetController(); + } +} + void PlayerController::SetMovement(const glm::vec3 &m) noexcept { if (dot(m, m) > 1.0f) { move_dir = normalize(m);