diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 95744e9f..418b704f 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1675,6 +1675,17 @@ void Game::renderWorker() { // ==================== tick ==================== +void Game::removeUnitFromSelection(const Unit *unit) { + Selection *selection= getGuiPtr()->getSelectionPtr(); + for(int i=0; i < selection->getCount(); ++i) { + const Unit *currentUnit = selection->getUnit(i); + if(currentUnit == unit) { + selection->unSelect(i); + break; + } + } +} + void Game::tick() { ProgramState::tick(); diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 455a98ec..83d88929 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -168,7 +168,7 @@ public: const GameCamera *getGameCamera() const {return &gameCamera;} GameCamera *getGameCameraPtr() {return &gameCamera;} const Commander *getCommander() const {return &commander;} - Gui *getGui() {return &gui;} + Gui *getGuiPtr() {return &gui;} const Gui *getGui() const {return &gui;} Commander *getCommander() {return &commander;} Console *getConsole() {return &console;} @@ -178,6 +178,8 @@ public: Program *getProgram() {return program;} + void removeUnitFromSelection(const Unit *unit); + bool getPaused(); void setPaused(bool value, bool forceAllowPauseStateChange=false); const int getTotalRenderFps() const {return totalRenderFps;} diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 4387952a..4f32d928 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -164,6 +164,7 @@ public: const Mouse3d *getMouse3d() const {return &mouse3d;} const Display *getDisplay() const {return &display;} const Selection *getSelection() const {return &selection;} + Selection *getSelectionPtr() {return &selection;} const Object *getSelectedResourceObject() const; Object *getHighlightedResourceObject() const; Unit *getHighlightedUnit() const; diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 430c0e18..641a4812 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -552,6 +552,7 @@ Unit::~Unit() { Renderer &renderer= Renderer::getInstance(); renderer.removeUnitFromQuadCache(this); + game->removeUnitFromSelection(this); //MutexSafeWrapper safeMutex1(&mutexDeletedUnits,string(__FILE__) + "_" + intToStr(__LINE__)); //deletedUnits[this]=true; @@ -2716,7 +2717,11 @@ bool Unit::morph(const MorphCommandType *mct){ // ==================== PRIVATE ==================== float Unit::computeHeight(const Vec2i &pos) const{ + //printf("CRASHING FOR UNIT: %d alive = %d\n",this->getId(),this->isAlive()); + //printf("[%s]\n",this->getType()->getName().c_str()); if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { + //printf("CRASHING FOR UNIT: %d [%s] alive = %d\n",this->getId(),this->getType()->getName().c_str(),this->isAlive()); + //abort(); throw runtime_error("#7 Invalid path position = " + pos.getString()); } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index b290a507..6935d749 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -60,7 +60,7 @@ UnitUpdater::UnitUpdater() { void UnitUpdater::init(Game *game){ this->game= game; - this->gui= game->getGui(); + this->gui= game->getGuiPtr(); this->gameCamera= game->getGameCamera(); this->world= game->getWorld(); this->map= world->getMap();