There was a problem with trying out the zlib routines on Linux, but I fixed them, and here's how.
I added sfxr.cpp and ssfxr.cpp to the engine's SConscript, and zlibengn.cpp to common's SConscript. That got it to build under Linux with scons.
Attempting to run engine with DeflateFile() got me a long message, including this stack trace.
======= Backtrace: =========
/lib/libc.so.6[0xa7bd6ee4]
/lib/libc.so.6(cfree+0x9c)[0xa7bd87bc]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xa7d9e971]
./engine[0x80cea6d]
./engine[0x80d07bd]
/usr/lib/libjs.so(js_Invoke+0xa92)[0xa7f6c33f]
/usr/lib/libjs.so(js_Interpret+0x7184)[0xa7f7390c]
/usr/lib/libjs.so(js_Execute+0x2f6)[0xa7f796d9]
/usr/lib/libjs.so(JS_EvaluateUCScriptForPrincipals+0x90)[0xa7f40a37]
/usr/lib/libjs.so(JS_EvaluateUCScript+0x43)[0xa7f40abc]
/usr/lib/libjs.so(JS_EvaluateScript+0x68)[0xa7f43785]
./engine[0x80bae4c]
./engine[0x8053b9f]
./engine[0x80e04aa]
./engine[0x80e09c6]
./engine[0x80e0d1a]
./engine[0x812b905]
/lib/libc.so.6(__libc_start_main+0xe5)[0xa7b816c5]
./engine[0x804d4f1]
I searched for info on reading Linux stack traces and found
this, which told me about the
addr2line command. Given a binary and an address, it could print the file and line from which it came.
I used addr2line on all of the ./engine lines, which got me this:
[tung@eee linux]$ addr2line -e engine 0x80cea6d
/home/tung/Projects/sphere/source/engine/script.cpp:395
[tung@eee linux]$ addr2line -e engine 0x80d07bd
/home/tung/Projects/sphere/source/engine/script.cpp:7184
[tung@eee linux]$ addr2line -e engine 0x80bae4c 0x8053b9f 0x80e04aa 0x80e09c6 0x80e0d1a 0x812b905
/home/tung/Projects/sphere/source/engine/script.cpp:536
/home/tung/Projects/sphere/source/engine/engine.cpp:171
/home/tung/Projects/sphere/source/engine/sphere.cpp:284
/home/tung/Projects/sphere/source/engine/sphere.cpp:351
/home/tung/Projects/sphere/source/engine/sphere.cpp:91
/home/tung/Projects/sphere/source/engine/unix/unix_main.cpp:211
[tung@eee linux]$ addr2line -e engine 0x804d4f1
??:0
The stack is in order from the function that caused the error, to the function that called that one, and so on to the top. So source/engine/script.cpp line 395 is where I headed.
With CVS annotate, I found
who last edited script.cpp at line 395: futureboynil. The
changeset shows him adding/changing a function on last Friday (27 Feb 2009): DoesFileExist.
Line 395 of source/engine/script.cpp looks like this:
static bool DoesFileExist(const char* pathandfile)
{
FILE *f = fopen(pathandfile, "r");
bool found = f ? true: false;
if(found) fclose(f);
delete f;
return found; // <- line 395
}
As it turns out, the offending line is not the return, but it's pretty close: the delete. Since C FILE handles aren't meant to be free()'d (or delete'd), the program crashed. Removing the line makes DeflateFile() and InflateFile() work as expected under Linux. Problem solved.
@fbnil: It's recommended that you use #include <cmath> instead of #include <math.h>, which is explained
here.
Also, avoid tabs, since the rest of the script.cpp file and other files use spaces for indentation.