Skip to content

Commit

Permalink
Map: Don't force exit if there's a problem reading saved FOW data
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Jan 13, 2025
1 parent 448cc01 commit c02687c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Engine fixes:
* Fixed books not closing properly when trying to load another book with an invalid filename.
* Fixed combat text being shown for zero damage reflect.
* Added validation to player XP table parsing to ensure that XP thresholds are not less than those for previous levels.
* Errors in saved fog-of-war data no longer causes a forced exit & mod reset.
* Android: Fix 'Flare' directory not being automatically created.
* Android: Added a dialog to direct the player to the wiki page for installing if no game data is found.

Expand Down
34 changes: 27 additions & 7 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ int Map::load(const std::string& fname) {
if (infile.open(ss.str(), !FileParser::MOD_FILE, FileParser::ERROR_NORMAL)) {
while (infile.next()) {
if (infile.section == "layer") {
loadLayer(infile);
if (!loadLayer(infile, !EXIT_ON_FAIL)) {
for (size_t i = layers.size(); i > 0; i--) {
if (layernames[i] == "fow_fog") {
layernames.erase(layernames.begin() + i);
layers.erase(layers.begin() + i);
}
else if (layernames[i] == "fow_dark") {
layernames.erase(layernames.begin() + i);
layers.erase(layers.begin() + i);
}
}
break;
}
}
}
infile.close();
Expand Down Expand Up @@ -248,7 +260,7 @@ void Map::loadHeader(FileParser &infile) {
}
}

void Map::loadLayer(FileParser &infile) {
bool Map::loadLayer(FileParser &infile, bool exit_on_fail) {
if (infile.key == "type") {
// @ATTR layer.type|string|Map layer type.
layers.resize(layers.size()+1);
Expand All @@ -262,9 +274,12 @@ void Map::loadLayer(FileParser &infile) {
// @ATTR layer.format|string|Format for map layer, must be 'dec'
if (infile.val != "dec") {
infile.error("Map: The format of a layer must be 'dec'!");
Utils::logErrorDialog("Map: The format of a layer must be 'dec'!");
mods->resetModConfig();
Utils::Exit(1);
if (exit_on_fail) {
Utils::logErrorDialog("Map: The format of a layer must be 'dec'!");
mods->resetModConfig();
Utils::Exit(1);
}
return false;
}
}
else if (infile.key == "data") {
Expand All @@ -285,8 +300,11 @@ void Map::loadLayer(FileParser &infile) {
}
if (comma_count != w) {
infile.error("Map: A row of layer data has a width not equal to %d.", w);
mods->resetModConfig();
Utils::Exit(1);
if (exit_on_fail) {
mods->resetModConfig();
Utils::Exit(1);
}
return false;
}

for (int i=0; i<w; i++)
Expand All @@ -296,6 +314,8 @@ void Map::loadLayer(FileParser &infile) {
else {
infile.error("Map: '%s' is not a valid key.", infile.key.c_str());
}

return true;
}

void Map::loadEnemyGroup(FileParser &infile, Map_Group *group) {
Expand Down
4 changes: 3 additions & 1 deletion src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ class Map_Enemy {

class Map {
protected:
static const bool EXIT_ON_FAIL = true;

void loadHeader(FileParser &infile);
void loadLayer(FileParser &infile);
bool loadLayer(FileParser &infile, bool exit_on_fail = EXIT_ON_FAIL);
void loadEnemyGroup(FileParser &infile, Map_Group *group);
void loadNPC(FileParser &infile);

Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 91);
Version VersionInfo::ENGINE(1, 14, 92);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit c02687c

Please sign in to comment.