From 916cba3b7b9dea6459febb90d24565cf4c0a8b2a Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 26 Oct 2015 10:05:08 +0100 Subject: [PATCH] remove self on player controller destruct fixes segfault when the world is being simulated after the player exits (like e.g. on a server :>) --- doc/todo | 4 ---- src/ui/PlayerController.hpp | 1 + src/ui/ui.cpp | 6 ++++++ 3 files changed, 7 insertions(+), 4 deletions(-) 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); -- 2.39.2