Permalink
Browse files

catch potential ParseExceptions when loading saves, use bson error ha…

…ndler to prevent exit(-5)
  • Loading branch information...
jacob1 committed Aug 12, 2016
1 parent 97a9f41 commit 6dc1c222bcc5a45263e2189823d523b514fe0462
Showing with 16 additions and 2 deletions.
  1. +6 −0 src/client/GameSave.cpp
  2. +10 −2 src/simulation/Simulation.cpp
@@ -439,6 +439,11 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
fanVelYPtr = (float*)fanVelYPtrNew;
}
void bson_error_handler(const char *err)
{
throw ParseException(ParseException::Corrupt, "BSON error when parsing save");
}
void GameSave::readOPS(char * data, int dataLength)
{
unsigned char * inputData = (unsigned char*)data, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL;
@@ -500,6 +505,7 @@ void GameSave::readOPS(char * data, int dataLength)
if (BZ2_bzBuffToBuffDecompress((char*)bsonData, &bsonDataLen, (char*)(inputData+12), inputDataLen-12, 0, 0))
throw ParseException(ParseException::Corrupt, "Unable to decompress");
set_bson_err_handler(bson_error_handler);
bson_init_data(&b, (char*)bsonData);
bson_iterator_init(&iter, &b);
@@ -33,8 +33,16 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
{
int blockX, blockY, x, y, r;
if(!save) return 1;
save->Expand();
if (!save)
return 1;
try
{
save->Expand();
}
catch (ParseException)
{
return 1;
}
//Align to blockMap
blockX = (fullX + CELL/2)/CELL;

0 comments on commit 6dc1c22

Please sign in to comment.