Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible crashes #3311

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ static void addConstructorEffect(STRUCTURE *psStruct)
{
/* This needs fixing - it's an arse effect! */
const Vector2i size = psStruct->size() * TILE_UNITS / 4;
ASSERT_OR_RETURN(, size.x > 0 && size.y > 0, "Zero-size building?: %s", (psStruct && psStruct->pStructureType) ? psStruct->pStructureType->id.toUtf8().c_str() : "<null>");
Vector3i temp;
temp.x = psStruct->pos.x + ((rand() % (2 * size.x)) - size.x);
temp.y = map_TileHeight(map_coord(psStruct->pos.x), map_coord(psStruct->pos.y)) + (psStruct->sDisplay.imd->max.y / 6);
Expand Down
19 changes: 11 additions & 8 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,16 +1525,19 @@ void orderDroidBase(DROID *psDroid, DROID_ORDER_DATA *psOrder)
objTrace(psDroid->id, "Starting new construction effort of %s", psOrder->psStats ? getStatsName(psOrder->psStats) : "NULL");
break;
case DORDER_BUILDMODULE:
//build a module onto the structure
if (!isConstructionDroid(psDroid) || psOrder->index < nextModuleToBuild((STRUCTURE *)psOrder->psObj, -1))
{
break;
//build a module onto the structure
if (!isConstructionDroid(psDroid) || psOrder->index < nextModuleToBuild((STRUCTURE *)psOrder->psObj, -1))
{
break;
}
STRUCTURE_STATS *psStats = getModuleStat((STRUCTURE *)psOrder->psObj);
ASSERT_OR_RETURN(, psStats != nullptr, "should have found a module stats");
psDroid->order = DroidOrder(DORDER_BUILD, psStats, psOrder->psObj->pos.xy(), 0);
ASSERT_OR_RETURN(, !psDroid->order.psStats || psDroid->order.psStats->type != REF_DEMOLISH, "Cannot build demolition");
actionDroid(psDroid, DACTION_BUILD, psOrder->psObj->pos.x, psOrder->psObj->pos.y);
objTrace(psDroid->id, "Starting new upgrade of %s", psOrder->psStats ? getStatsName(psOrder->psStats) : "NULL");
}
psDroid->order = DroidOrder(DORDER_BUILD, getModuleStat((STRUCTURE *)psOrder->psObj), psOrder->psObj->pos.xy(), 0);
ASSERT_OR_RETURN(, psDroid->order.psStats != nullptr, "should have found a module stats");
ASSERT_OR_RETURN(, !psDroid->order.psStats || psDroid->order.psStats->type != REF_DEMOLISH, "Cannot build demolition");
actionDroid(psDroid, DACTION_BUILD, psOrder->psObj->pos.x, psOrder->psObj->pos.y);
objTrace(psDroid->id, "Starting new upgrade of %s", psOrder->psStats ? getStatsName(psOrder->psStats) : "NULL");
break;
case DORDER_HELPBUILD:
// help to build a structure that is starting to be built
Expand Down
Loading