Crash in initstate_r()

Posted by Zeno on Sat 28 Jan 2006 01:08 AM — 5 posts, 15,021 views.

USA #0
I'm trying to run the Phantasia4 source:
http://www.phantasia4.com/download.html (down)
Can be played here: http://www.phantasia4.org

It compiled fine, but when I try to run it, it crashes. Under gdb, it seems to crash in /lib/libc.so.6 in the function initstate_r() which is not part of the source. Anyone know why it's crashing?

In the source, this is the line that calls initstate_r:
   /* seed the random number generator */
    initstate_r (time(NULL), (char *)&randomStateBuffer, STATELEN,
       (struct random_data *)&randData);
Amended on Thu 25 Nov 2010 05:29 PM by Zeno
USA #1
See: http://lists.debian.org/debian-glibc/2006/01/msg00037.html

Are you compiling with gcc 4.1? That could be it. I don't know anything else about this, I just googled for initstate_r and found that...
USA #2
I saw that. But no, I'm using gcc 3.3.6.
USA #3
Never really figured it out. I ended up using initstate() instead of initstate_r(), as well as srandom() etc. It's running now, but I don't know what effects those changes may have.
USA #4
Quote:
The initstate_r function behaves exactly like the initstate function except that it uses and modifies the state in the object pointed to by the fourth parameter instead of the global state.
What that means is that initstate_r is re-entrant, and can be used, for example, in multithreaded applications.

I suspect that multiple simultaneous calls to initstate would cause havoc, since the function apparently uses a single global buffer for its data.