Skip to content

Commit 32d587f

Browse files
committed
Missing error handling
1 parent b8d9147 commit 32d587f

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎src/Engine/SurfaceSet.cpp‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,28 @@ void SurfaceSet::loadPck(const std::string &pck, const std::string &tab)
7575
int nframes = 0;
7676

7777
// Load TAB and get image offsets
78-
std::ifstream offsetFile (tab.c_str(), std::ios::in | std::ios::binary);
79-
if (!offsetFile)
80-
{
81-
nframes = 1;
82-
Surface *surface = new Surface(_width, _height);
83-
_frames[0] = surface;
84-
}
85-
else
78+
if (!tab.empty())
8679
{
80+
std::ifstream offsetFile(tab.c_str(), std::ios::in | std::ios::binary);
81+
if (!offsetFile)
82+
{
83+
throw Exception(tab + " not found");
84+
}
8785
Uint16 off;
88-
while (offsetFile.read((char*)&off, sizeof(off)))
86+
while (offsetFile.read((char*) &off, sizeof(off)))
8987
{
9088
off = SDL_SwapLE16(off);
9189
Surface *surface = new Surface(_width, _height);
9290
_frames[nframes] = surface;
9391
nframes++;
9492
}
93+
offsetFile.close();
94+
}
95+
else
96+
{
97+
nframes = 1;
98+
Surface *surface = new Surface(_width, _height);
99+
_frames[0] = surface;
95100
}
96101

97102
// Load PCX and put pixels in surfaces
@@ -140,7 +145,6 @@ void SurfaceSet::loadPck(const std::string &pck, const std::string &tab)
140145
}
141146

142147
imgFile.close();
143-
offsetFile.close();
144148
}
145149

146150
/**

‎src/Resource/XcomResourcePack.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ void XcomResourcePack::loadBattlescapeResources()
757757
for (std::vector<std::string>::iterator i = usets.begin(); i != usets.end(); ++i)
758758
{
759759
std::string path = units + *i;
760-
std::string tab = path.substr(0, path.length() - 4) + ".TAB";
760+
std::string tab = CrossPlatform::getDataFile("UNITS/" + i->substr(0, i->length() - 4) + ".TAB");
761761
std::transform(i->begin(), i->end(), i->begin(), toupper);
762762
if (*i != "BIGOBS.PCK")
763763
_sets[*i] = new SurfaceSet(32, 40);

0 commit comments

Comments
 (0)