aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2011-04-19 21:02:27 +1000
committerPaul Gilbert2011-04-19 21:02:27 +1000
commit5dcfd1e32c185e88b09a3ff1341aaf78b674572b (patch)
tree4fe644352cae7e509eda6282a436025bfd95380c /engines
parentd18f8e8564de7feb890ca8fe183c6508c64acc41 (diff)
downloadscummvm-rg350-5dcfd1e32c185e88b09a3ff1341aaf78b674572b.tar.gz
scummvm-rg350-5dcfd1e32c185e88b09a3ff1341aaf78b674572b.tar.bz2
scummvm-rg350-5dcfd1e32c185e88b09a3ff1341aaf78b674572b.zip
TSAGE: Reworked the saving code to fix crashes
Note that this undoes the recent compilation fix for GCC, since it didn't work. For now, used an explicit void ** conversion as previously suggested.
Diffstat (limited to 'engines')
-rw-r--r--engines/tsage/core.h1
-rw-r--r--engines/tsage/saveload.cpp34
-rw-r--r--engines/tsage/saveload.h8
-rw-r--r--engines/tsage/scenes.cpp8
-rw-r--r--engines/tsage/scenes.h1
5 files changed, 45 insertions, 7 deletions
diff --git a/engines/tsage/core.h b/engines/tsage/core.h
index 6508d1576a..c18984fd45 100644
--- a/engines/tsage/core.h
+++ b/engines/tsage/core.h
@@ -728,6 +728,7 @@ public:
}
SynchronisedList<SceneObject *>::iterator begin() { return _objList.begin(); }
SynchronisedList<SceneObject *>::iterator end() { return _objList.end(); }
+ int size() const { return _objList.size(); }
bool contains(SceneObject *sceneObj) { return tSage::contains(_objList, sceneObj); }
void push_back(SceneObject *sceneObj) { _objList.push_back(sceneObj); }
void push_front(SceneObject *sceneObj) { _objList.push_front(sceneObj); }
diff --git a/engines/tsage/saveload.cpp b/engines/tsage/saveload.cpp
index 594d30fa3c..73c9d02cb5 100644
--- a/engines/tsage/saveload.cpp
+++ b/engines/tsage/saveload.cpp
@@ -151,13 +151,13 @@ Common::Error Saver::save(int slot, const Common::String &saveName) {
}
Common::Error Saver::restore(int slot) {
- assert(!getMacroSaveFlag());
+ assert(!getMacroRestoreFlag());
// Signal any objects registered for notification
_loadNotifiers.notify(false);
// Set fields
- _macroSaveFlag = true;
+ _macroRestoreFlag = true;
_saveSlot = slot;
_unresolvedPtrs.clear();
@@ -335,7 +335,7 @@ bool Saver::savegamesExist() const {
*/
int Saver::blockIndexOf(SavedObject *p) {
int objIndex = 1;
- SynchronisedList<SavedObject *>::iterator iObj;
+ Common::List<SavedObject *>::iterator iObj;
for (iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
SavedObject *iObjP = *iObj;
@@ -347,6 +347,30 @@ int Saver::blockIndexOf(SavedObject *p) {
}
/**
+ * Returns the number of objects in the object list registry
+ */
+int Saver::getObjectCount() const {
+ int count = 0;
+ Common::List<SavedObject *>::const_iterator i;
+
+ for (i = _objList.begin(); i != _objList.end(); ++i, ++count)
+ ;
+ return count;
+}
+
+/**
+ * List any currently active objects
+ */
+void Saver::listObjects() {
+ Common::List<SavedObject *>::iterator i;
+ int count = 1;
+
+ for (i = _objList.begin(); i != _objList.end(); ++i, ++count)
+ debug("%d - %s", count, (*i)->getClassName().c_str());
+ debug("");
+}
+
+/**
* Returns the pointer associated with the specified object index
*/
void Saver::resolveLoadPointers() {
@@ -358,12 +382,14 @@ void Saver::resolveLoadPointers() {
int objIndex = 1;
for (SynchronisedList<SavedObject *>::iterator iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
Common::List<SavedObjectRef>::iterator iPtr;
+ SavedObject *pObj = *iObj;
for (iPtr = _unresolvedPtrs.begin(); iPtr != _unresolvedPtrs.end(); ) {
SavedObjectRef &r = *iPtr;
if (r._objIndex == objIndex) {
// Found an unresolved pointer to this object
- *r._savedObject = *iObj;
+ SavedObject **objPP = r._savedObject;
+ *objPP = pObj;
iPtr = _unresolvedPtrs.erase(iPtr);
} else {
++iPtr;
diff --git a/engines/tsage/saveload.h b/engines/tsage/saveload.h
index 945d144ae5..c45271b8fc 100644
--- a/engines/tsage/saveload.h
+++ b/engines/tsage/saveload.h
@@ -54,8 +54,8 @@ struct tSageSavegameHeader {
// FIXME: workaround to supress spurious strict-alias warnings on older GCC
// versions. this should be resolved with the savegame rewrite
#define SYNC_POINTER(x) do { \
- SavedObject *y = (SavedObject *)x; \
- s.syncPointer(&y); \
+ SavedObject **y = (SavedObject **)((void *)&x); \
+ s.syncPointer(y); \
} while (false)
#define SYNC_ENUM(FIELD, TYPE) int v_##FIELD = (int)FIELD; s.syncAsUint16LE(v_##FIELD); \
@@ -176,7 +176,7 @@ typedef SavedObject *(*SavedObjectFactory)(const Common::String &className);
class Saver {
private:
- SynchronisedList<SavedObject *> _objList;
+ Common::List<SavedObject *> _objList;
FunctionList<bool> _saveNotifiers;
FunctionList<bool> _loadNotifiers;
Common::List<SaveListener *> _listeners;
@@ -212,6 +212,8 @@ public:
bool getMacroSaveFlag() const { return _macroSaveFlag; }
bool getMacroRestoreFlag() const { return _macroRestoreFlag; }
int blockIndexOf(SavedObject *p);
+ int getObjectCount() const;
+ void listObjects();
};
extern Saver *_saver;
diff --git a/engines/tsage/scenes.cpp b/engines/tsage/scenes.cpp
index 748e8662fd..fc82f168ea 100644
--- a/engines/tsage/scenes.cpp
+++ b/engines/tsage/scenes.cpp
@@ -27,6 +27,7 @@
#include "tsage/globals.h"
#include "tsage/ringworld_logic.h"
#include "tsage/tsage.h"
+#include "tsage/saveload.h"
namespace tSage {
@@ -39,6 +40,7 @@ SceneManager::SceneManager() {
_fadeMode = FADEMODE_GRADUAL;
_scrollerRect = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
_saver->addListener(this);
+ _objectCount = 0;
}
SceneManager::~SceneManager() {
@@ -107,6 +109,12 @@ void SceneManager::sceneChange() {
// Free any regions
disposeRegions();
+ // Ensure that the same number of objects are registered now as when the scene started
+ if (_objectCount > 0) {
+ assert(_objectCount == _saver->getObjectCount());
+ }
+ _objectCount = _saver->getObjectCount();
+
// Instantiate and set the new scene
_scene = getNewScene();
_scene->postInit();
diff --git a/engines/tsage/scenes.h b/engines/tsage/scenes.h
index 1a6f92745d..6353972984 100644
--- a/engines/tsage/scenes.h
+++ b/engines/tsage/scenes.h
@@ -88,6 +88,7 @@ public:
int _sceneLoadCount;
Rect _scrollerRect;
SceneObjectList _altSceneObjects;
+ int _objectCount;
public:
SceneManager();
virtual ~SceneManager();