Game Development Community

Problem with HorizCompassCtrl

by Steve Kilcollins · in Torque Game Engine · 10/26/2004 (4:25 pm) · 5 replies

I got this the other day from tork.beffy.dev and I have a weird situation where when I compile a debug build it works fine. When I build release, the UIcompass.jpg shows up and moves (that part works fine)but the UIbackgroundcompass.png doesn't show.

Anyone else have this problem or something similiar?

I wondered if it would have been changes in my base code. So, I took the base 1.3 TGE and added in the horizcompassctl.cc and .h and I got the same results.

Any thoughts, ideas as to what could be wrong?

#1
10/28/2004 (7:02 pm)
Well, I found where the problem is,, but don't understand why?

Here is the code
void HorizCompassCtrl::onRender(Point2I offset, const RectI &updateRect)
..
..
..
	  Con::printf("C: coming in offset x: %i offset y: %i", offset.x,offset.y);

  	  MatrixF cameraMatrix = query.cameraMatrix;
	  Point3F cameraRot;
	  cameraMatrix.getColumn(1, &cameraRot);
	  cameraRot.neg();
	  cameraRot.z = 0;
	  Con::printf("D: coming in offset x: %i offset y: %i", offset.x,offset.y);

	  mcompassOffset = Vector2dToOffset(cameraRot);
[b]
 //  Con::printf("E: coming in offset x: %i offset y: %i", offset.x,offset.y);
 [/b]
	  RectI dstRect(mBounds.point.x + BorderOffset.x/2 + mcompassOffset, mBounds.point.y + BorderOffset.y/2,
					texture->bitmapWidth, texture->bitmapHeight);


	  dglDrawBitmapStretch(mTextureHandle, dstRect, false);

What is really weird is the offset.y is getting zero'd out. so I put in the printf's to try and figure out where. and its zero'd out at the "D"

Here is the log
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 0
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 0
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 0

now the weird part is if I uncomment line the printf "E" the offset.y retains is value and doesn't lose it.

void HorizCompassCtrl::onRender(Point2I offset, const RectI &updateRect)
..
..
..
	  Con::printf("C: coming in offset x: %i offset y: %i", offset.x,offset.y);

  	  MatrixF cameraMatrix = query.cameraMatrix;
	  Point3F cameraRot;
	  cameraMatrix.getColumn(1, &cameraRot);
	  cameraRot.neg();
	  cameraRot.z = 0;
	  Con::printf("D: coming in offset x: %i offset y: %i", offset.x,offset.y);

	  mcompassOffset = Vector2dToOffset(cameraRot);
    [b]
	  Con::printf("E: coming in offset x: %i offset y: %i", offset.x,offset.y);  
[/b]
	  RectI dstRect(mBounds.point.x + BorderOffset.x/2 + mcompassOffset, mBounds.point.y + BorderOffset.y/2,
					texture->bitmapWidth, texture->bitmapHeight);


	  dglDrawBitmapStretch(mTextureHandle, dstRect, false);

and the log
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 143
E: coming in offset x: 191 offset y: 143
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 143
E: coming in offset x: 191 offset y: 143
A:  coming in offset x: 191 offset y: 143
B: coming in offset x: 191 offset y: 143
C: coming in offset x: 191 offset y: 143
D: coming in offset x: 191 offset y: 143
E: coming in offset x: 191 offset y: 143


This only happens in a release build. The debug build is fine, the offset.y always retains is value.

I can't figure out or see why it is doing that? Anyone have any idea's why?
#2
10/29/2004 (1:15 pm)
That's pretty mysterious. Maybe you have some memory corruption happening elsewhere in the engine?
#3
10/29/2004 (1:47 pm)
Hey Ben..

I thought of that.. but the only really modifications that I have done is create a couple of my own gui controls, and applied couple of resources. Thinking that I may have done something somewhere that would cause this, I took a clean copy of the head (from last week) and added the .cc and .h resource, compiled and it acts the same way.

And the worse part is, I can't do a debug run on it,, cause in debug it works fine.

I can get around it by putting the RectI that I need (not shown here which is a few lines of code below what is shown) to just the beginning of the function. And rectI works if I do that.

I'm one of those people that it bothers the hell out of me that I can't find/fix it and have to do a work-around (the bug won).
#4
10/29/2004 (3:19 pm)
I found it! Whoohoo.

I had to change
struct CameraQuery query;

	  GameProcessCameraQuery(&query);

  	  MatrixF cameraMatrix = query.cameraMatrix;
	  Point3F cameraRot;
	  cameraMatrix.getColumn(1, &cameraRot);
	  cameraRot.neg();
	  cameraRot.z = 0;

to this

CameraQuery *query = new CameraQuery;
	  GameProcessCameraQuery(query);

	  query->cameraMatrix.getColumn(1, &cameraRot);
	  cameraRot.neg();
	  cameraRot.z = 0;
	  delete query;

Looks like the GameProcessCameraQuery was somehow messing up the &query pointer/information, and getting rid of the extra copy of the MatrixF cameraMatrix = query.cameraMatrix;

So I decided to make a new Cameraquery pointer. I figured with a new the memory would be better protected (don't know if that is correct or not) but it now works perfectly in release build. I'm thinking that the debug build would protect the memories automatically, but release build wouldn't have the protection. Again,, I could be wrong in my assumptions.
#5
10/29/2004 (3:48 pm)
Odd, got that resource working without modifications recently.. I _think_.