Game Development Community

GuiWindowCtrl crash question

by Drew Parker · in Torque Game Engine · 08/19/2005 (11:40 am) · 4 replies

I'm getting a crash from GuiWindowCtrl in PositionButtons(). First off, let me say my scripts are doing something I'm sure is wrong, I just don't know what it is. It's causing one of my dynamic GUIs to try to start up too early. Basically, they are calling .setPosition() on a window, which eventually causes the crash.

I was able to stop the crash by moving one line from onWake(). Then, the GUI opens up fine, no other quirky behavior. Here is the code:

Where the crash takes place, in PositionButtons() (called by resize()), you see this:

S32 buttonWidth = mBitmapBounds[BmpStates * BmpClose].extent.x;
   S32 buttonHeight = mBitmapBounds[BmpStates * BmpClose].extent.y;

The crash takes pace because mBitmapBounds is pointing to garbage. So, when you try to access it, a crash occurs.

But in another function, namely onWake(), you see this:
mBitmapBounds = mProfile->mBitmapArrayRects.address();
   S32 buttonWidth = mBitmapBounds[BmpStates * BmpClose].extent.x;
   S32 buttonHeight = mBitmapBounds[BmpStates * BmpClose].extent.y;

When I moved
mBitmapBounds = mProfile->mBitmapArrayRects.address();
to the function PositionButtons(), to make the two code blocks match, it stopped crashing.

So my question is, since onWake() is called quite a lot, and assigning mBitmapBounds happens there, is it ok if I also move it to PositionButtons()? Is there a reason why it's left out?

I'm going to keep looking into my scripts to find out what going on, but since I came across this I thought I'd ask.
Thanks to any who reply!

#1
08/19/2005 (3:27 pm)
The fix looks fine.

You're calling setPosition on your GUI before its awoken?
#2
08/19/2005 (5:35 pm)
Hey Ben, thanks for the reply :)

I guess that's what's happening by accident?

While debugging my problem, I thought of a reason it may be crashing. I haven't had a chance to test it out yet, but I think it may be happening because I'm trying to move a window that is not in the active canvas content. See, my scripts got messed up because a movie is playing (and showing a different GUI on the canvas), but it *thinks* it needs to display some in-game GUI on the Playgui file. So, while the movie GUI is up, the script is calling .setPosition() on a GUI in the playgui which is not being shown.

So I'm guessing calling .setPosition() on a window not on the canvas causes the crash. But I'll have to test that out to check. Anyway, it's a bug in my scripts that's causing that. :)

- Drew
#3
08/20/2005 (6:31 am)
Ok, I think I discovered the specific problem.

My scripts were calling setPosition() on a GUI that was not on the canvas. This caused the mBitmapBounds to not be initialized by onWake(), then cause a crash when it is accessed in PositionButtons() since it pointed to garbage.

I tested this out by calling setPosition() on one of my GUI elements not on the canvas (not the same one I had problems with initially), and it still caused a crash. When I changed the code like mentioned above, it also stops that crash... so I guess I'll be leaving it in then :)
#4
08/20/2005 (3:02 pm)
Very interesting... Thanks for the explanation!