PDA

View Full Version : Questions about Error #1030: Stack depth is unbalanced.



jclaine
September 23rd, 2009, 03:31 PM
Ok, so I'm making a game in as3 & cs4 while coding in flashdevelop.

The game requires me to keep track of and tell robots to go to an x position and build something. There is some priority as to what robot gets selected based on their current task. So i have 3 arrays set up in a globalvars class, I then sort these arrays in order of least priority. There will be instances of the array being completely empty so I check to see if the GLOBALVARS.aBobIdle is undefined. When I exicute the code does not trace any of the trace functions and traces out a bunch of lines in the output pannel that look like this

3:debugline 19
stack:
scope: [global Object$]
locals: Scripts::BOBHandler$ Boolean int String? flash.display::MovieClip? *
5:getlocal0
stack: Scripts::BOBHandler$
scope: [global Object$]
locals: Scripts::BOBHandler$ Boolean int String? flash.display::MovieClip? *

at the end of it all is

VerifyError: Error #1030: Stack depth is unbalanced. 0 != 1.

at Scripts::BOBHandler$/BOBSort()
at Scripts.Supports_Build::Iron_Build/addBuildOBot()[C:\Documents and Settings\gd13jordan\Desktop\LOCAL HD KeepItUp\Prototypes\GamePlay\Scripts\Supports_Buil d\Iron_Build.as:121]
at Scripts::SupportMouseListener/addBuildOBot()[C:\Documents and Settings\gd13jordan\Desktop\LOCAL HD KeepItUp\Prototypes\GamePlay\Scripts\SupportMouseL istener.as:111]

Should i be doing something diffrent for the array comparison, if so how do i detect an empty array?

Here is the class, I can upload the rleated classes if needed but this seems to be isolated to this class.



package Scripts {
import flash.display.MovieClip;
import Scripts.GLOBALVARS;
/**
* ...
* @author Jordan Laine
*/
public class BOBHandler {

public static var nBOBX:int

public var main;
//public var nBOBX:int;

public function BOBHandler () {
main = this;
}

public static function BOBSort(bDouble:Boolean, nLoc:int, runState:String, mcSupport:MovieClip) {
nBOBX = mcSupport.x;
var mcBob:MovieClip;
if (GLOBALVARS.aBobIdle[0] != undefined) {
trace("Im in here 1");
GLOBALVARS.aBobIdle.sort(BOBLocationUpDate);
if (runState == "repair") {
mcBob = GLOBALVARS.aBobIdle[0];
GLOBALVARS.aBobRepair.unshift(mcBob);
GLOBALVARS.aBobIdle.splice[1, 0];
} else if (runState == "build") {
mcBob = GLOBALVARS.aBobIdle[0];
GLOBALVARS.aBobBuild.unshift(mcBob);
GLOBALVARS.aBobIdle.splice[1, 0];
}
GLOBALVARS.aBobIdle[0].Move(bDouble, nLoc, runState, mcSupport);
} else if (GLOBALVARS.aBobRepair[0] != undefined) {
trace("Im in here 2");
GLOBALVARS.aBobRepair.sort(BOBLocationUpDate);
if (runState == "repair") {
/*mcBob = GLOBALVARS.aBobIdel[0];
GLOBALVARS.aBobRepair.unshift(mcBob);
GLOBALVARS.aBobIdel.splice[1, 0];*/
trace("this BOB was repairing");
} else if (runState == "build") {
mcBob = GLOBALVARS.aBobRepair[0];
GLOBALVARS.aBobBuild.unshift(mcBob);
GLOBALVARS.aBobRepair.splice[1, 0];
}
GLOBALVARS.aBobRepair[0].Move(bDouble, nLoc, runState, mcSupport);
} else {
trace("Im in here 3");
GLOBALVARS.aBobBuild.sort(BOBLocationUpDate);
if (runState == "repair") {
mcBob = GLOBALVARS.aBobBuild[0];
GLOBALVARS.aBobRepair.unshift(mcBob);
GLOBALVARS.aBobBuild.splice[1, 0];
} else if (runState == "build") {
/* mcBob = GLOBALVARS.aBobRepair[0];
GLOBALVARS.aBobBuild.unshift(mcBob);
GLOBALVARS.aBobRepair.splice[1, 0]; */
trace("this BOB was Building");
}
GLOBALVARS.aBobBuild[0].Move(bDouble, nLoc, runState, mcSupport);
}
}

public static function BOBLocationUpDate (a:MovieClip, b:MovieClip):Number {
var aX:int = a.x;
var bX:int = b.x;
aX - nBOBX;
bX - nBOBX;
if(aX > bX) {
return -1;
} else if (aX < bX) {
return 1;
} else {
return 0;
}
}
}
}

jclaine
September 23rd, 2009, 03:36 PM
comparing .length to != undefined and .length to 0 on the arrays gets the same results.

sinclairc5
September 23rd, 2009, 04:10 PM
At a glance i cant tell at


if (GLOBALVARS.aBobIdle[0] != undefined) {wether aBobIdle is a defined array or not. I suggest wrapping this if statement with


if( GLOBALVARS.aBobIdle is Array )
{
if (GLOBALVARS.aBobIdle[0] != undefined) { etc.......
}
else
{
trace( "bingo my array has not been defined!" );
}just as a test measure to ensure your getting a defined Array. This process goes for all the else if statements too. if any of these arrays are null then using aBobIdle[0] is refering to a null object reference and the compiler will throw an Error.

jclaine
September 23rd, 2009, 04:55 PM
The array gets defined at run time in the GLOBALVARS class and gets emptied as bots get allocated to the other arrays.





//excerpt from the GLOBALVARS constructor function
public static var aBob:Array = [];
public static var aBobBuild:Array = [];
public static var aBobIdle:Array = [];
public static var aBobRepair:Array = [];
public static var aBobAutoRepair:Array = [];
public static var aBuildList:Array = [];


If I trace the array before the function is called it looks like this



public function addBuildOBot () {
if (nBobInSupportFake < 10) {
trace("flash can suck a ****");
nBobInSupportFake++;
upDateBobCounter();
var bDouble:Boolean;
if (sSupportID != "Titanium") {
bDouble = false;
} else {
bDouble = true;
}
trace ("GLOBALVARS.aBobIdle = " + GLOBALVARS.aBobIdle.length);
BOBHandler.BOBSort(bDouble, nLocation, "build", this);
} else {

}

}


Output



flash can suck a ****
GLOBALVARS.aBobIdle = 0
verify Scripts::BOBHandler$/BOBSort()
stack:
scope: [global Object$]...

jclaine
September 23rd, 2009, 08:35 PM
I've got it narrowed down to


GLOBALVARS.aBobIdle.splice[1, 0];


syntax is correct and vars are all relative, anyone have an idea why this would be functional?

_kp
September 23rd, 2009, 09:53 PM
GLOBALVARS.aBobIdle.splice(1, 0);

jclaine
September 23rd, 2009, 11:23 PM
jesus... thank you. I guess programming all night caught up to me. The output really through me for a loop.