aboutsummaryrefslogtreecommitdiff
path: root/engines/cge/cge_main.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2011-08-06 15:29:49 +1000
committerPaul Gilbert2011-08-06 15:29:49 +1000
commitc961597988ab0e9d9ed7dff5b317d620bcc84153 (patch)
tree4a6b7e0efd6f579d2350645453ae877fc5f29a4b /engines/cge/cge_main.cpp
parentf5d38d82d0c805f6c6d2d58999791cc69f29a024 (diff)
downloadscummvm-rg350-c961597988ab0e9d9ed7dff5b317d620bcc84153.tar.gz
scummvm-rg350-c961597988ab0e9d9ed7dff5b317d620bcc84153.tar.bz2
scummvm-rg350-c961597988ab0e9d9ed7dff5b317d620bcc84153.zip
CGE: Fixed non-portability in loading _heroXY array
Diffstat (limited to 'engines/cge/cge_main.cpp')
-rw-r--r--engines/cge/cge_main.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp
index 71089c5ea9..41bb68417c 100644
--- a/engines/cge/cge_main.cpp
+++ b/engines/cge/cge_main.cpp
@@ -26,6 +26,7 @@
*/
#include "common/scummsys.h"
+#include "common/endian.h"
#include "common/memstream.h"
#include "common/savefile.h"
#include "common/serializer.h"
@@ -110,11 +111,12 @@ void CGEEngine::syncHeader(Common::Serializer &s) {
for (i = 0; i < 4; i++)
s.syncAsUint16LE(_flag[i]);
- initCaveValues();
if (s.isLoading()) {
- //TODO: Fix the memory leak when the game is already running
- _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax);
- _barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax));
+ // Reinitialise cave values
+ free(_heroXY);
+ free(_barriers);
+
+ initCaveValues();
}
for (i = 0; i < _caveMax; i++) {
@@ -429,9 +431,18 @@ void CGEEngine::loadHeroXY() {
debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()");
INI_FILE cf(progName(".HXY"));
+ uint16 x, y;
+
memset(_heroXY, 0, sizeof(_heroXY));
- if (!cf._error)
- cf.read((uint8 *)(&_heroXY),sizeof(*(&_heroXY)));
+ if (!cf._error) {
+ for (int i = 0; i < _caveMax; ++i) {
+ cf.read((byte *)&x, 2);
+ cf.read((byte *)&y, 2);
+
+ _heroXY[i]._x = (int16)FROM_LE_16(x);
+ _heroXY[i]._y = (int16)FROM_LE_16(y);
+ }
+ }
}
void CGEEngine::loadMapping() {