Skip to content

Commit

Permalink
- update code to fix crashes on missing game data
Browse files Browse the repository at this point in the history
- add missing game data warning to gamefiles
  • Loading branch information
dgengin committed Jun 21, 2016
1 parent f1dbf7c commit 619fe98
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 20 deletions.
Empty file modified android/jni/.gitignore
100755 → 100644
Empty file.
21 changes: 6 additions & 15 deletions gamefiles/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
"mountFile": [
{ "file": "DIABDAT.zip", "append": true }
],
"saveDir": ".diablo",
"icon": {
"file":"res/icon.png"
},
"cursor": {
"show": false
},
"load": "settings.json",
"load": "res/actions.json",
"load": "res/fonts.json",
"load": "res/music.json",
"load": "res/palettes.json",
"load": "res/sounds.json",
"load": "res/textures.json",
"load": "ui/splashScreen.json"
"action": {
"name": "if.fileExists",
"param1": "ui_art/title.pcx",
"then": { "name": "load", "file": "ui/loadMain.json" },
"else": { "name": "load", "file": "ui/dataMissing.json" }
}
}
22 changes: 22 additions & 0 deletions gamefiles/ui/dataMissing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"keyboard": {
"key": ["enter", " ", "esc"],
"action": { "name": "game.close" }
},
"font": {
"id": "liberationSerif",
"file": "res/LiberationSerif-Regular.ttf"
},
"button": {
"id": "quit",
"font": "liberationSerif",
"fontSize": 28,
"color": "0xFFFFFF",
"position": [320, 240],
"anchor": "none",
"horizontalAlign": "center",
"verticalAlign": "center",
"text": "Error loading DIABDAT.zip\nMake sure the game data is present.",
"onClick": "game.close"
}
}
17 changes: 17 additions & 0 deletions gamefiles/ui/loadMain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"saveDir": ".diablo",
"icon": {
"file":"res/icon.png"
},
"cursor": {
"show": false
},
"load": "settings.json",
"load": "res/actions.json",
"load": "res/fonts.json",
"load": "res/music.json",
"load": "res/palettes.json",
"load": "res/sounds.json",
"load": "res/textures.json",
"load": "ui/splashScreen.json"
}
5 changes: 5 additions & 0 deletions src/Dun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Dun::Dun(const std::string& filename)
{
sf::PhysFSStream file(filename);

if (file.hasError() == true)
{
return;
}

int16_t temp;
file.read(&temp, 2);
width = temp;
Expand Down
9 changes: 8 additions & 1 deletion src/Font2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ class Font2 : public sf::Font
public:
Font2(const std::shared_ptr<sf::PhysFSStream>& file_) : file(file_) {}

bool load() { return loadFromStream(*file); }
bool load()
{
if (file == nullptr || file->hasError() == true)
{
return false;
}
return loadFromStream(*file);
}
};
2 changes: 1 addition & 1 deletion src/LoadingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void LoadingScreen::setProgress(int percent_)
else
{
sf::Vector2f newSize(barSize);
newSize.x *= (percent_ / 100.0f);
newSize.x = std::round(newSize.x * (percent_ / 100.0f));
progressBar.setSize(newSize);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Min::Min(const std::string& filename, size_t minSize)
{
sf::PhysFSStream file(filename);

if (file.hasError() == true)
{
return;
}

auto numPillars = file.getSize() / (minSize * 2);

file.seek(0);
Expand Down
4 changes: 4 additions & 0 deletions src/Movie2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Movie2 : public UIObject

bool load()
{
if (file == nullptr || file->hasError() == true)
{
return false;
}
bool ret = movie.openFromStream(*file);
if (ret == true)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Music2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ class Music2 : public sf::NonCopyable
Music2(const char* file_) : file(std::make_unique<sf::PhysFSStream>(file_)),
music(std::make_unique<sf::Music>()) {}

bool load() { return music->openFromStream(*file); }
bool load()
{
if (file == nullptr || file->hasError() == true)
{
return false;
}
return music->openFromStream(*file);
}

void play() { music->play(); }
void pause() { music->pause(); }
Expand Down
2 changes: 1 addition & 1 deletion src/Palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Palette::Palette(const char* file)
{
sf::PhysFSStream stream(file);

if (stream.getSize() < 768)
if (stream.hasError() == true || stream.getSize() < 768)
{
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Parser/ParseBitmapFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ namespace Parser
else if (isValidString(elem, "textureId"))
{
img = parseTextureImg(game, elem);
auto imgSize = img.getSize();
if (imgSize.x == 0 || imgSize.y == 0)
{
return;
}
texture = std::make_shared<sf::Texture>();
texture->loadFromImage(img);
texture->setSmooth(getBool(elem, "smooth"));
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ParseText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Parser
return nullptr;
}

auto size = getUInt(elem, "fontSize");
auto size = getUInt(elem, "fontSize", 12);
auto text = std::make_unique<StringText>(displayText, *font, size);
text->setColor(getColor(elem, "color", sf::Color::White));
text->setHorizontalAlign(GameUtils::getHorizontalAlignment(getString(elem, "horizontalAlign")));
Expand Down
5 changes: 5 additions & 0 deletions src/Sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Sol::Sol(const std::string& path)
{
sf::PhysFSStream file(path);

if (file.hasError() == true)
{
return;
}

auto size = (unsigned)file.getSize();
data.resize(size);

Expand Down

0 comments on commit 619fe98

Please sign in to comment.