aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorWalter van Niftrik2010-01-01 23:48:22 +0000
committerWalter van Niftrik2010-01-01 23:48:22 +0000
commit205f7437ea668be302e22b278a106f27af23fabf (patch)
treeb93b8fa5dc7996852b4dde908069da1041387197 /engines/sci/engine
parent137744c40c5e5ab717c364a113cf5e83ca104663 (diff)
downloadscummvm-rg350-205f7437ea668be302e22b278a106f27af23fabf.tar.gz
scummvm-rg350-205f7437ea668be302e22b278a106f27af23fabf.tar.bz2
scummvm-rg350-205f7437ea668be302e22b278a106f27af23fabf.zip
SCI: Fix segfault in dual-language KQ5.
svn-id: r46864
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/seg_manager.cpp7
-rw-r--r--engines/sci/engine/segment.h6
-rw-r--r--engines/sci/engine/vm.cpp15
3 files changed, 24 insertions, 4 deletions
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 4983d9b347..d68853a593 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -568,6 +568,13 @@ Object *Script::scriptObjInit(reg_t obj_pos) {
return obj;
}
+void Script::scriptObjRemove(reg_t obj_pos) {
+ if (getSciVersion() < SCI_VERSION_1_1)
+ obj_pos.offset += 8;
+
+ _objects.erase(obj_pos.toUint16());
+}
+
LocalVariables *SegManager::allocLocalsSegment(Script *scr, int count) {
if (!count) { // No locals
scr->_localsSegment = 0;
diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h
index d8cdd91da8..62f970722e 100644
--- a/engines/sci/engine/segment.h
+++ b/engines/sci/engine/segment.h
@@ -381,6 +381,12 @@ public:
Object *scriptObjInit(reg_t obj_pos);
/**
+ * Removes a script object
+ * @param obj_pos Location (segment, offset) of the object.
+ */
+ void scriptObjRemove(reg_t obj_pos);
+
+ /**
* Processes a relocation block witin a script
* This function is idempotent, but it must only be called after all
* objects have been instantiated, or a run-time error will occur.
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 9eb3b85981..4792454f1b 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -1644,11 +1644,18 @@ int script_instantiate_sci0(ResourceManager *resMan, SegManager *segMan, int scr
obj->setSpeciesSelector(INST_LOOKUP_CLASS(obj->getSpeciesSelector().offset));
Object *baseObj = segMan->getObject(obj->getSpeciesSelector());
- obj->setVarCount(baseObj->getVarCount());
- // Copy base from species class, as we need its selector IDs
- obj->_baseObj = baseObj->_baseObj;
- obj->setSuperClassSelector(INST_LOOKUP_CLASS(obj->getSuperClassSelector().offset));
+ if (baseObj) {
+ obj->setVarCount(baseObj->getVarCount());
+ // Copy base from species class, as we need its selector IDs
+ obj->_baseObj = baseObj->_baseObj;
+
+ obj->setSuperClassSelector(INST_LOOKUP_CLASS(obj->getSuperClassSelector().offset));
+ } else {
+ warning("Failed to locate base object for object at %04X:%04X; skipping", PRINT_REG(addr));
+
+ scr->scriptObjRemove(addr);
+ }
} // if object or class
break;
case SCI_OBJ_POINTERS: // A relocation table