aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel
diff options
context:
space:
mode:
authorMax Horn2009-10-27 00:38:41 +0000
committerMax Horn2009-10-27 00:38:41 +0000
commit4b681f7ec7e42ea17ed97c80372cf564a8648682 (patch)
treeac437f4301fb614a2cd50a96226b02ee4194c6d6 /engines/tinsel
parent02636c20714156327524b6a85b36dae64f6eeb06 (diff)
downloadscummvm-rg350-4b681f7ec7e42ea17ed97c80372cf564a8648682.tar.gz
scummvm-rg350-4b681f7ec7e42ea17ed97c80372cf564a8648682.tar.bz2
scummvm-rg350-4b681f7ec7e42ea17ed97c80372cf564a8648682.zip
TINSEL: Add some debugging code; fix LockMem() regression
svn-id: r45430
Diffstat (limited to 'engines/tinsel')
-rw-r--r--engines/tinsel/handle.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp
index d144c1c86f..8c88608fa9 100644
--- a/engines/tinsel/handle.cpp
+++ b/engines/tinsel/handle.cpp
@@ -41,7 +41,7 @@ namespace Tinsel {
//----------------- EXTERNAL GLOBAL DATA --------------------
#ifdef DEBUG
-static bool bLockedScene = 0;
+static uint32 s_lockedScene = 0;
#endif
@@ -322,7 +322,7 @@ void LoadFile(MEMHANDLE *pH) {
}
/**
- * Returns the address of a image, given its memory handle.
+ * Compute and return the address specified by a SCNHANDLE.
* @param offset Handle and offset to data
*/
byte *LockMem(SCNHANDLE offset) {
@@ -332,6 +332,11 @@ byte *LockMem(SCNHANDLE offset) {
// range check the memory handle
assert(handle < numHandles);
+#ifdef DEBUG
+ if (handle != s_lockedScene)
+ warning(" Calling LockMem(0x%x), handle %d differs from active scene %d", offset, handle, s_lockedScene);
+#endif
+
pH = handleTable + handle;
if (pH->filesize & fPreload) {
@@ -341,10 +346,10 @@ byte *LockMem(SCNHANDLE offset) {
if (offset < cdBaseHandle || offset >= cdTopHandle)
error("Overlapping (in time) CD-plays");
- // may have been discarded, make sure memory is allocated
- MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle);
-
- if (!(pH->filesize & fLoaded)) {
+ // May have been discarded, if so, we have to reload
+ if (!MemoryDeref(pH->_node)) {
+ // Data was discarded, we have to reload
+ MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle);
LoadCDGraphData(pH);
@@ -352,22 +357,24 @@ byte *LockMem(SCNHANDLE offset) {
MemoryTouch(pH->_node);
}
+ // make sure address is valid
+ assert(pH->filesize & fLoaded);
+
offset -= cdBaseHandle;
} else {
- // may have been discarded, make sure memory is allocated
- MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
-
- if (!(pH->filesize & fLoaded)) {
+ if (!MemoryDeref(pH->_node)) {
+ // Data was discarded, we have to reload
+ MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
if (TinselV2) {
SetCD(pH->flags2 & fAllCds);
CdCD(nullContext);
}
LoadFile(pH);
-
- // make sure address is valid
- assert(pH->filesize & fLoaded);
}
+
+ // make sure address is valid
+ assert(pH->filesize & fLoaded);
}
return MemoryDeref(pH->_node) + (offset & OFFSETMASK);
@@ -383,7 +390,7 @@ void LockScene(SCNHANDLE offset) {
MEMHANDLE *pH; // points to table entry
#ifdef DEBUG
- assert(!bLockedScene); // Trying to lock more than one scene
+ assert(0 == s_lockedScene); // Trying to lock more than one scene
#endif
// range check the memory handle
@@ -399,7 +406,7 @@ void LockScene(SCNHANDLE offset) {
MemoryLock(pH->_node);
#ifdef DEBUG
- bLockedScene = true;
+ s_lockedScene = handle;
#endif
}
}
@@ -423,7 +430,7 @@ void UnlockScene(SCNHANDLE offset) {
MemoryUnlock(pH->_node);
#ifdef DEBUG
- bLockedScene = false;
+ s_lockedScene = 0;
#endif
}
}