catch potential ParseExceptions when loading saves, use bson error handler to prevent exit(-5)
This commit is contained in:
parent
97a9f41ab9
commit
6dc1c222bc
@ -439,6 +439,11 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
|
|||||||
fanVelYPtr = (float*)fanVelYPtrNew;
|
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)
|
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;
|
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))
|
if (BZ2_bzBuffToBuffDecompress((char*)bsonData, &bsonDataLen, (char*)(inputData+12), inputDataLen-12, 0, 0))
|
||||||
throw ParseException(ParseException::Corrupt, "Unable to decompress");
|
throw ParseException(ParseException::Corrupt, "Unable to decompress");
|
||||||
|
|
||||||
|
set_bson_err_handler(bson_error_handler);
|
||||||
bson_init_data(&b, (char*)bsonData);
|
bson_init_data(&b, (char*)bsonData);
|
||||||
bson_iterator_init(&iter, &b);
|
bson_iterator_init(&iter, &b);
|
||||||
|
|
||||||
|
@ -33,8 +33,16 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
|||||||
{
|
{
|
||||||
int blockX, blockY, x, y, r;
|
int blockX, blockY, x, y, r;
|
||||||
|
|
||||||
if(!save) return 1;
|
if (!save)
|
||||||
|
return 1;
|
||||||
|
try
|
||||||
|
{
|
||||||
save->Expand();
|
save->Expand();
|
||||||
|
}
|
||||||
|
catch (ParseException)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//Align to blockMap
|
//Align to blockMap
|
||||||
blockX = (fullX + CELL/2)/CELL;
|
blockX = (fullX + CELL/2)/CELL;
|
||||||
|
Loading…
Reference in New Issue
Block a user