Permalink
Browse files

Fixed an issue in robot death logic that caused a dangling pointer de…

…reference crash.
  • Loading branch information...
ldicker83 committed Jan 10, 2019
1 parent 1236088 commit 3dde746df74076e03387ee6c1344aa452c2350f4
Showing with 15 additions and 4 deletions.
  1. +1 −0 CHANGELOG.md
  2. +3 −0 src/Constants/Strings.h
  3. +11 −4 src/States/MapViewState.cpp
@@ -26,6 +26,7 @@ User interface overhaul.
- Fixed an oversight that caused ListBox to sort all of its items regardless of whether it was in sorted mode or not.
- Addressed a usability issue with the underlying NAS2D library that sometimes resulted in incorrect sizing and positioning of UI elements when resizing the game window.
- Fixed 'Quit' button in Planet Selection view being positioned incorrectly on window resize.
- Fixed a mistake in robot aging logic that resulted in a dangling pointer dereference. Thanks to OPU user jem7650 for bringing this to my attention!


## [0.7.6] - 2018-07-06
@@ -32,6 +32,9 @@ namespace constants
const std::string MINE_YIELD_MEDIUM = "Medium";
const std::string MINE_YIELD_HIGH = "High";

const std::string ROBOT_BREAKDOWN_TITLE = "Robot Breakdown";
const std::string ROBOT_BREAKDOWN_MESSAGE = "Your %s at location %i, %i has broken down. It will not be able to complete its task and will be removed from your inventory.";

// =====================================
// = SAVE GAMES
// =====================================
@@ -597,12 +597,13 @@ void MapViewState::onMouseDoubleClick(EventHandler::MouseButton button, int x, i
if (_t && _t->thingIsStructure())
{
Structure* _s = _t->structure();
mReportsUiCallback();

if (_s->isFactory()) { MAIN_REPORTS_UI->selectFactoryPanel(_s); }
else if (_s->isWarehouse()) { MAIN_REPORTS_UI->selectWarehousePanel(_s); }
else if (_s->isMineFacility()) { }
else { }
else if (_s->isMineFacility() || _s->structureClass() == Structure::CLASS_SMELTER) { MAIN_REPORTS_UI->selectMinePanel(_s); }
else { return; } // avoids showing the full-screen UI on unhandled structures.

mReportsUiCallback();
}
}
}
@@ -1110,13 +1111,19 @@ void MapViewState::updateRobots()
{
std::cout << "dead robot" << std::endl;

doNonFatalErrorMessage(constants::ROBOT_BREAKDOWN_TITLE, string_format(constants::ROBOT_BREAKDOWN_MESSAGE, robot_it->first->name().c_str(), robot_it->second->x(), robot_it->second->y()));

if (robot_it->second->thing() == robot_it->first)
{
robot_it->second->removeThing();
}

mRobotPool.erase(robot_it->first);
delete robot_it->first;
robot_it = mRobotList.erase(robot_it);
}
else if(robot_it->first->idle())
{
// Make sure that we're the robot from a Tile and not something else
if (robot_it->second->thing() == robot_it->first)
{
robot_it->second->removeThing();

0 comments on commit 3dde746

Please sign in to comment.