dimasdallas / oglsuperbible5

Automatically exported from code.google.com/p/oglsuperbible5
0 stars 0 forks source link

Crash of all sphereworld programs #25

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run any Sphereworld program

What is the expected output? What do you see instead?
No crash and the program running according to what is stated in the book.

What version of the product are you using? On what operating system?
Revision 192.
OS: Gentoo Linux for AMD 64 arch.

Please provide any additional information below.
My graphics chipset is an NVIDIA GeForce 8800 GTX

Below is the backtrace of Sphereworld via gdb:

(gdb) run
Starting program: 
/home/roland/Projets/cpp-prj/oglsuperbible5-read-only/Linux/Chapter04/SphereWorl
d/SphereWorld 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000401dfc in GLMatrixStack::GetMatrix (this=0x0) at 
../../../Src/GLTools/include/GLMatrixStack.h:165
165                     const M3DMatrix44f& GetMatrix(void) { return 
pStack[stackPointer]; }
(gdb) backtrace
#0  0x0000000000401dfc in GLMatrixStack::GetMatrix (this=0x0) at 
../../../Src/GLTools/include/GLMatrixStack.h:165
#1  0x0000000000402390 in GLGeometryTransform::GetModelViewProjectionMatrix 
(this=0x649760) at ../../../Src/GLTools/include/GLGeometryTransform.h:53
#2  0x0000000000401a93 in RenderScene () at 
../../../Src/Chapter04/SphereWorld/SphereWorld.cpp:102
#3  0x00007ffff787ef18 in ?? () from /usr/lib/libglut.so.3
#4  0x00007ffff7882ae9 in fgEnumWindows () from /usr/lib/libglut.so.3
#5  0x00007ffff787f403 in glutMainLoopEvent () from /usr/lib/libglut.so.3
#6  0x00007ffff787fdb0 in glutMainLoop () from /usr/lib/libglut.so.3
#7  0x0000000000401da3 in main (argc=1, argv=0x7fffffffd9d8) at 
../../../Src/Chapter04/SphereWorld/SphereWorld.cpp:144

The backtrace are similar for the other Sphereworld programs.

Original issue reported on code.google.com by r.evera...@gmail.com on 14 Apr 2011 at 2:38

GoogleCodeExporter commented 9 years ago
Hi,

I debug the SphereWorld program and I found the problem. The glutMainLoop() 
function calls the callback functions in this order the first time:

- RenderScene()
- ChangeSize()

Due to this order of execution, the object modelViewMatrix is not correctly 
initialize, leading to a crash when the object's methods try to access some of 
its attributes (pStack in this case).

The only workaround I found is to call ChangeSize(), with the correct 
parameters, explicitly between SetupRC() and glutMainLoop().

I am using freeglut 2.6.0 as provided by my distro.

Original comment by r.evera...@gmail.com on 19 Apr 2011 at 8:46

GoogleCodeExporter commented 9 years ago
The object transformPipeline is not properly initialized, because the call to 
the function transformPipeline.SetMatrixStacks() is made in ChangeSize(), which 
is too late.

To get this code working just move the line
transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
from ChangeSize to SetupRC().

Original comment by bac...@itp.uni-frankfurt.de on 28 Jul 2011 at 7:30

GoogleCodeExporter commented 9 years ago
Tried both of the above - same crash, 

First-chance exception at 0x68f592ed in SphereWorld4.exe: 0xC0000005: Access 
violation reading location 0xbaadf0ed.
Unhandled exception at 0x68f592ed in SphereWorld4.exe: 0xC0000005: Access 
violation reading location 0xbaadf0ed.

at this point in the program:

    // Randomly place the spheres
    for(int i = 0; i < NUM_SPHERES; i++) {
        GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        spheres[i].SetOrigin(x, 0.0f, z);
        }

Original comment by findra...@gmail.com on 22 Aug 2012 at 9:36