Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix bad positions in savegame, add asserts to catch bad values earlier
  • Loading branch information
Eli2 committed Aug 19, 2016
1 parent d864446 commit 0050f2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/game/NPC.cpp
Expand Up @@ -980,6 +980,7 @@ void ARX_PHYSICS_Apply() {

io->requestRoomUpdate = true;
io->pos = pbox->vert[0].pos;
arx_assert(isallfinite(io->pos));

continue;
}
Expand Down Expand Up @@ -2546,6 +2547,7 @@ static void ManageNPCMovement(Entity * io)
}

// Now update lastpos values for next call use...
arx_assert(isallfinite(io->pos));
io->lastpos = io->pos;
}

Expand Down
21 changes: 20 additions & 1 deletion src/scene/ChangeLevel.cpp
Expand Up @@ -1982,11 +1982,24 @@ static Entity * ARX_CHANGELEVEL_Pop_IO(const std::string & idString, EntityInsta
io->ioflags = EntityFlags::load(ais->ioflags); // TODO save/load flags

io->ioflags &= ~IO_FREEZESCRIPT;

io->initpos = ais->initpos.toVec3();
arx_assert(isallfinite(io->initpos));

io->pos = ais->pos.toVec3();
if(!isallfinite(io->pos)) {
LogWarning << "Found bad entity pos in " << io->idString();
io->pos = io->initpos;
}

io->lastpos = ais->lastpos.toVec3();
if(!isallfinite(io->lastpos)) {
LogWarning << "Found bad entity lastpos in " << io->idString();
io->lastpos = io->initpos;
}

io->move = ais->move.toVec3();
io->lastmove = ais->lastmove.toVec3();
io->initpos = ais->initpos.toVec3();
io->initangle = ais->initangle;
io->angle = ais->angle;
io->scale = ais->scale;
Expand Down Expand Up @@ -2076,6 +2089,12 @@ static Entity * ARX_CHANGELEVEL_Pop_IO(const std::string & idString, EntityInsta

io->spellcast_data = ais->spellcast_data;
io->physics = ais->physics;

if(!isallfinite(io->physics.cyl.origin)) {
LogWarning << "Found bad entity physics.cyl.origin in " << io->idString();
io->physics.cyl.origin = io->initpos;
}

assert(SAVED_MAX_ANIM_LAYERS == MAX_ANIM_LAYERS);
std::copy(ais->animlayer, ais->animlayer + SAVED_MAX_ANIM_LAYERS, io->animlayer);

Expand Down

0 comments on commit 0050f2f

Please sign in to comment.