aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorTorbjörn Andersson2004-10-22 07:18:01 +0000
committerTorbjörn Andersson2004-10-22 07:18:01 +0000
commit4115b54b004db5f8879d92f01bea17a52008af5d (patch)
tree981ef77c01a945af075a9293758f99f8bb684ea6 /saga
parenteb7fe9cee4f248887ac7d18d84b0637c14a094fc (diff)
downloadscummvm-rg350-4115b54b004db5f8879d92f01bea17a52008af5d.tar.gz
scummvm-rg350-4115b54b004db5f8879d92f01bea17a52008af5d.tar.bz2
scummvm-rg350-4115b54b004db5f8879d92f01bea17a52008af5d.zip
Fixed two of my own stupid bugs:
* The length of a script data buffer is measured in words, not bytes. * In the long run, I'm sure it'll work better if the data buffers do not point to recently freed data. svn-id: r15640
Diffstat (limited to 'saga')
-rw-r--r--saga/sthread.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 5e9cc785bf..b80d58817e 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -37,7 +37,7 @@ namespace Saga {
void Script::setFramePtr(R_SCRIPT_THREAD *thread, int newPtr) {
thread->framePtr = newPtr;
- dataBuffer(3)->len = 2 * (ARRAYSIZE(thread->stackBuf) - thread->framePtr);
+ dataBuffer(3)->len = ARRAYSIZE(thread->stackBuf) - thread->framePtr;
dataBuffer(3)->data = (SDataWord_T *) &(thread->stackBuf[newPtr]);
}
@@ -54,17 +54,18 @@ R_SCRIPT_THREAD *Script::SThreadCreate() {
return NULL;
}
+ new_node = ys_dll_add_head(threadList(), new_thread, sizeof *new_thread);
+ free(new_thread);
+
+ new_thread = (R_SCRIPT_THREAD *)ys_dll_get_data(new_node);
+
new_thread->stackPtr = ARRAYSIZE(new_thread->stackBuf) - 1;
setFramePtr(new_thread, new_thread->stackPtr);
- dataBuffer(4)->len = sizeof(new_thread->threadVars);
+ dataBuffer(4)->len = ARRAYSIZE(new_thread->threadVars);
dataBuffer(4)->data = new_thread->threadVars;
- new_node = ys_dll_add_head(threadList(), new_thread, sizeof *new_thread);
-
- free(new_thread);
-
- return (R_SCRIPT_THREAD *)ys_dll_get_data(new_node);
+ return new_thread;
}
int Script::SThreadDestroy(R_SCRIPT_THREAD *thread) {
@@ -208,7 +209,7 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
MemoryReadStream scriptS(currentScript()->bytecode->bytecode_p, currentScript()->bytecode->bytecode_len);
- dataBuffer(2)->len = currentScript()->bytecode->bytecode_len;
+ dataBuffer(2)->len = currentScript()->bytecode->bytecode_len / sizeof(SDataWord_T);
dataBuffer(2)->data = (SDataWord_T *) currentScript()->bytecode->bytecode_p;
scriptS.seek(thread->i_offset);