OpenGL problem in Xcode deployment build

Post: #1
I have a large OpenGL game in the final stages of development but as soon as I switch the Xcode build to Deployment mode, the shadows from the characters are drawn a long way away from where they should be.

The difference appears to be in gltMakeShadowMatrix() that I found in the OpenGL SuperBible book. In deployment build, I get the wrong values in elements 9 to 15 of the destMat. In development mode everything works as expected.

Appreciate any help here as I'm stuck

void gltMakeShadowMatrix(GLTVector3 vPoints[3], GLTVector4 vLightPos, GLTMatrix destMat)
    GLTVector4 vPlaneEquation;
    GLfloat dot;

    gltGetPlaneEquation(vPoints[0], vPoints[1], vPoints[2], vPlaneEquation);
    // Dot product of plane and light position
    dot =   vPlaneEquation[0]*vLightPos[0] +
            vPlaneEquation[1]*vLightPos[1] +
            vPlaneEquation[2]*vLightPos[2] +

    // Now do the projection
    // First column
    destMat[0] = dot - vLightPos[0] * vPlaneEquation[0];
    destMat[4] = 0.0f - vLightPos[0] * vPlaneEquation[1];
    destMat[8] = 0.0f - vLightPos[0] * vPlaneEquation[2];
    destMat[12] = 0.0f - vLightPos[0] * vPlaneEquation[3];

    // Second column
    destMat[1] = 0.0f - vLightPos[1] * vPlaneEquation[0];
    destMat[5] = dot - vLightPos[1] * vPlaneEquation[1];
    destMat[9] = 0.0f - vLightPos[1] * vPlaneEquation[2];
    destMat[13] = 0.0f - vLightPos[1] * vPlaneEquation[3];

    // Third Column
    destMat[2] = 0.0f - vLightPos[2] * vPlaneEquation[0];
    destMat[6] = 0.0f - vLightPos[2] * vPlaneEquation[1];
    destMat[10] = dot - vLightPos[2] * vPlaneEquation[2];
    destMat[14] = 0.0f - vLightPos[2] * vPlaneEquation[3];

    // Fourth Column
    destMat[3] = 0.0f - vLightPos[3] * vPlaneEquation[0];
    destMat[7] = 0.0f - vLightPos[3] * vPlaneEquation[1];
    destMat[11] = 0.0f - vLightPos[3] * vPlaneEquation[2];
    destMat[15] = dot - vLightPos[3] * vPlaneEquation[3];

Edit: added code tags
Quote this message in a reply
Posts: 509
Joined: 2002.09
Post: #2
One of the most common solutions is to simply do a Clean All targets and rebuild. It may or may not work though...

"When you dream, there are no rules..."
Quote this message in a reply
Post: #3
Thanks for the suggestion. I did indeed try that and have repeatedly switched back and forward from dev to deployment build with a clean at each stage but still get the shadows in different places.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #4
I'd suggest comparing the assembly code generated in debug and release modes. It won't be fun, but it probably tells you what you need to know about what's been done differently.
Quote this message in a reply
Post: #5
Thanks for the idea. I have just looked at both assembly code listings and the 2 listings are almost completely different for every line of code throughout the program (ie not just the suspect area). I'm amazed at how different the listings are so I haven't copied anything here as it would be too long.

Not sure where to go next with this - any further thoughts?
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #6
Most of the difference will be that the debug build will have lots of redundant loads and stores. The instructions that do the "grunt-work" of the math should be roughly the same, though probably in a different order.

One possible thing to look for is whether it's issuing fused multiply-add instructions (eg. fmadds/fmsubs) in the optimized build or not in the debug build, for example.

If it's all Greek to you, post both listings and we can take a look for you.

I'd also be printing out the floats, making sure you aren't getting NaNs in the optimized build where you're not in the debug build, for example.
Quote this message in a reply
Post: #7
OK - have been working around the printing of floats which still seem to be floats. However when I come back from the gltMakeShadowMatrix() call, I tried to force in the values for the matrix[9] thru [15]. No difference in results! However if I force the values just before I need to use the matrix, everything works under Deployment build. Development build continues to work exactly as required regardless.

So, I'm not sure where the problem now lies but I have an ugly fix. As I now have hit other problems around switching back and forth fullscreen to windows, I'm going to leave this for now.

Appreciate your help here as I have learnt much more about the ability to look into the assembly code. Regards.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 5,743 Jan 19, 2013 08:25 AM
Last Post: sealfin
  iPad, OpenGL ES, and XCode Instruments problem! Bandit 0 5,294 Dec 13, 2010 01:21 PM
Last Post: Bandit
  OpenGL global and local coordinate problem. mikey 4 6,536 May 26, 2009 08:48 AM
Last Post: mikey
  Simple OpenGL ES problem soulstorm 3 6,480 May 14, 2009 03:53 PM
Last Post: AnotherJake
  Opengl picking problem (zip file) papillon68 1 6,427 Mar 1, 2009 08:49 PM
Last Post: chronus