Mysterious source of instability

I’m the developer of the Sourceforge project Tronimation. I’ve been working on some improved primitives, but I’m hitting a stone wall. For some reason, a program that used to be 100% stable now crashes for no apparent reason every 5 minutes.

The improved primitive is currently the cube. Other than changes pieces to handle 7 rather then 2 object variables (not the problem), this is the only thing I can think of that’s the problem:

glVertex3f((GLfloat)-values.xsize, (GLfloat)-values.ysize,(GLfloat)-values.zsize); //-1 -1 -1 LEFT SIDE
glVertex3f((GLfloat)-values.xsize, (GLfloat)-values.ysize, (GLfloat)values.zsize); //-1 -1 1
glVertex3f((GLfloat)-values.xsizevalues.var0cosf(deg_to_radvalues.var5)cosf(deg_to_radvalues.var6), (GLfloat)values.ysize-values.ysizesinf(deg_to_radvalues.var4)sinf(deg_to_radvalues.var5),(GLfloat) values.zsizevalues.var2cosf(deg_to_radvalues.var4)cosf(deg_to_radvalues.var6)); //-1 1 1
glVertex3f((GLfloat)-values.xsizevalues.var0cosf(deg_to_radvalues.var5)cosf(deg_to_radvalues.var6), (GLfloat)values.ysize-values.ysizesinf(deg_to_radvalues.var4)sinf(deg_to_radvalues.var5),(GLfloat)-values.zsizevalues.var3cosf(deg_to_radvalues.var4)cosf(deg_to_radvalues. var6)); //-1 1 -1

This is the code for one side of the “cube.” Here is the typedef that values refers to:

typedef struct static_object { // Defines values to draw static objects
float xsize, ysize, zsize; // X-Y-Z Scale factors of object
float xpos, ypos, zpos; // Position
float lr,lg,lb, fr, fg, fb, alpha; // (l)ine and (f)ace colors
float xangle, yangle, zangle; // XYZ vectors to rotate around
int groupnum;
float var0, var1, var2, var3, var4, var5, var6; // Seven variables to do whatever you want
short int object_type;
short int object_render_options;
} static_object;

At first I thought that the problem was that I suddenly decided to perform sin/cos math on what were previously just numbers with maybe one multiply while not casting them to GLfloat. But I added GLfloat and it is not helping…

Here’s a copy-paste of the console output that happens:

[erik-k@erik Tronimation] ./tronimation 5163: binding file /usr/X11R6/lib/libglut.so.3 to /lib/tls/libc.so.6: normal symbol `exit' [GLIBC_2.0] Segmentation fault [erik-k@erik Tronimation] ./tronimation
5165: binding file ./tronimation to /lib/tls/libc.so.6: normal symbol sscanf' [GLIBC_2.0] lookup 0x08048000 0x00000688 -> 0x4026d000 0x0005f780 /1 sscanf 5165: binding file ./tronimation to /usr/lib/tls/libGL.so.1: normal symbol glColor4f’
lookup 0x08048000 0x00000748 → 0x40161000 0x00052588 /1 glColor4f
5165: binding file ./tronimation to /usr/lib/tls/libGL.so.1: normal symbol glBegin' lookup 0x08048000 0x000004a8 -> 0x40161000 0x00052028 /1 glBegin 5165: binding file ./tronimation to /usr/lib/tls/libGL.so.1: normal symbol glVertex3f’
lookup 0x08048000 0x000003f8 → 0x40161000 0x00053e28 /1 glVertex3f
5165: binding file ./tronimation to /lib/tls/libm.so.6: normal symbol cosf' [GLIBC_2.0] lookup 0x08048000 0x00000668 -> 0x4024a000 0x0000fd50 /1 cosf 5165: binding file ./tronimation to /lib/tls/libm.so.6: normal symbol sinf’ [GLIBC_2.0]
lookup 0x08048000 0x00000418 → 0x4024a000 0x00010910 /1 sinf
5165: binding file ./tronimation to /usr/lib/tls/libGL.so.1: normal symbol `glEnd’
lookup 0x08048000 0x00000768 -> 0x40161000 0x00052808 /1 glEnd
Segmentation fault

It’s like something is screwing up the internal state of GLUT and I have no idea where the problem is. I’m drawing a major WTF here… Can anyone help? If you want to read the rest of the source, I’m zipping up everything as-is and putting it up as a devel at TRONimation download | SourceForge.net after I post this.

Hi !

Could you run it in a debugger and find out the exact location where it crash ? that might make everything much easier.

Originally posted by mikael_aronsson:
[b]Hi !

Could you run it in a debugger and find out the exact location where it crash ? that might make everything much easier.[/b]
Okay. I ran it in gdb, and got the followingL

[erik-k@erik Tronimation]$ gdb ./tronimation
GNU gdb 6.0-2mdk (Mandrake Linux)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i586-mandrake-linux-gnu”…Using host libthread_db library “/lib/tls/libthread_db.so.1”.

(gdb) run
Starting program: /home/erik-k/programs/opengl/worldview/Tronimation/tronimation
4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /lib/tls/libc.so.6: normal symbol sscanf' [GLIBC_2.0] lookup 0x08048000 0x00000688 -> 0x4026d000 0x0005f780 /1 sscanf 4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /usr/lib/tls/libGL.so.1: normal symbol glColor4f’
lookup 0x08048000 0x00000748 -> 0x40161000 0x00052588 /1 glColor4f
4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /usr/lib/tls/libGL.so.1: normal symbol glBegin' lookup 0x08048000 0x000004a8 -> 0x40161000 0x00052028 /1 glBegin 4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /usr/lib/tls/libGL.so.1: normal symbol glVertex3f’
lookup 0x08048000 0x000003f8 -> 0x40161000 0x00053e28 /1 glVertex3f
4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /lib/tls/libm.so.6: normal symbol cosf' [GLIBC_2.0] lookup 0x08048000 0x00000668 -> 0x4024a000 0x0000fd50 /1 cosf 4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /lib/tls/libm.so.6: normal symbol sinf’ [GLIBC_2.0]
lookup 0x08048000 0x00000418 -> 0x4024a000 0x00010910 /1 sinf
4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /usr/lib/tls/libGL.so.1: normal symbol glEnd' lookup 0x08048000 0x00000768 -> 0x40161000 0x00052808 /1 glEnd 4426: binding file /home/erik-k/programs/opengl/worldview/Tronimation/tronimation to /usr/X11R6/lib/libglut.so.3: normal symbol glutDestroyWindow’
lookup 0x08048000 0x00000518 -> 0x4012a000 0x0001bf00 /1 glutDestroyWindow
4426: binding file /usr/X11R6/lib/libglut.so.3 to /usr/X11R6/lib/libglut.so.3: normal symbol `__glutDestroyWindow’

Program received signal SIGSEGV, Segmentation fault.
do_lookup (undef_name=0x4012d61a “__glutDestroyWindow”, hash=21811431, ref=0x4012b194, result=0xbffff344, scope=Variable “scope” is not available.
) at do-lookup.h:52
52 do-lookup.h: No such file or directory.
in do-lookup.h
(gdb) bt
#0 do_lookup (undef_name=0x4012d61a “__glutDestroyWindow”, hash=21811431, ref=0x4012b194, result=0xbffff344, scope=Variable “scope” is not available.
) at do-lookup.h:52
#1 0x40008dfd in _dl_do_lookup (undef_name=Variable “undef_name” is not available.
) at dl-lookup.c:738
#2 0x40008dc3 in _dl_debug_bindings (undef_name=Variable “undef_name” is not available.
) at dl-lookup.c:681
#3 0x40008090 in _dl_lookup_symbol (undef_name=Variable “undef_name” is not available.
) at dl-lookup.c:320
#4 0x4000c6f1 in fixup (l=Variable “l” is not available.
) at dl-runtime.c:102
#5 0x4000c890 in _dl_runtime_resolve () at dl-runtime.c:215
#6 0x40145f49 in glutDestroyWindow () from /usr/X11R6/lib/libglut.so.3
#7 0x4015fc10 in ?? () from /usr/X11R6/lib/libglut.so.3
(gdb) list
215 dl-runtime.c: No such file or directory.
in dl-runtime.c
(gdb) list
215 in dl-runtime.c
(gdb) step

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb)

I’m don’t know jack about debugging… The part starting with 4226: binding … was console output by Tronimation itself. After it crashed (upon my trying to exit) I ran bt. Then I tried stepping it and the window actually closed.