[Scummvm-cvs-logs] CVS: scummvm/saga sthread.cpp,1.31,1.32

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Fri Oct 22 00:23:47 CEST 2004


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28559

Modified Files:
	sthread.cpp 
Log Message:
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.


Index: sthread.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sthread.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- sthread.cpp	21 Oct 2004 06:49:11 -0000	1.31
+++ sthread.cpp	22 Oct 2004 07:18:01 -0000	1.32
@@ -37,7 +37,7 @@
 
 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 @@
 		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 @@
 
 	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);





More information about the Scummvm-git-logs mailing list