PDA

View Full Version : stack overflow?!


carn1x
10-19-2008, 07:54 PM
I'm trying to create a game which involves placing structures. One of the functions involved requires getting permission to place the structure. Currently I'm only using the structure as a placeholder while I work on other aspects. However I'm getting a strange error which I'm hoping to understand.

The problem surrounds the following code:

public function buildingPermission(pPoint:Object,pRadius:Number,pS tructureArray:Array):Boolean{
//trace(4);
var permission:Boolean=true;
return(permission);
}

Running this function outputs the following error:

verify BuildingManager/buildingPermission()
stack:
scope: [global Object$ BuildingManager$]
locals: BuildingManager Object? Number Array? *
0:getlocal0
stack: BuildingManager
scope: [global Object$ BuildingManager$]
locals: BuildingManager Object? Number Array? *
1:pushscope
stack:
scope: [global Object$ BuildingManager$] BuildingManager
locals: BuildingManager Object? Number Array? *
2:pushfalse
stack: Boolean
scope: [global Object$ BuildingManager$] BuildingManager
locals: BuildingManager Object? Number Array? *
3:setlocal 4
stack:
scope: [global Object$ BuildingManager$] BuildingManager
locals: BuildingManager Object? Number Array? Boolean
5:pushtrue
stack: Boolean
scope: [global Object$ BuildingManager$] BuildingManager
locals: BuildingManager Object? Number Array? Boolean
6:dup
VerifyError: Error #1023: Stack overflow occurred.
at BuildingManager/buildingPermission()
at BuildingManager/placementPermission()
at MouseManager/updateCursor()

Strangely if I remove the commenting from the function so that it actually runs the trace then the function runs perfectly fine, outputs the trace and the function returns true.

What's this all about then?

papillon68
10-19-2008, 08:39 PM
Quite odd behaviour: are you sure you are not messing with the array index passed to the function ?

carn1x
10-19-2008, 08:50 PM
no the code I've posted isn't editted for my own secrecy. It's literally what I'm running :S

Well the array in the parameters "pStructureArray" is currently empty, however I can't imagine that should have any effect as at no point in any of my code am I doing anything to that array yet.

Curtis Morley seems to go to some lengths to explain this issue, but well, I can't quite make sense of it, at least in terms of relating his example to my problem:

http://curtismorley.com/2007/08/19/flashflex-as3-error-1023-stack-overflow-occurred/

Somebody in the comments section does seem to be having a similar problem to me though. With a similarly odd "solution".

I had another crack by trying the "add something between declaring/setting the variable and returning it:

public function buildingPermission(pPoint:Object,pRadius:Number,pS tructureArray:Array):Boolean{
var permission:Boolean=true;
var b:Number=5;
return(permission);
}

I'm simply creating a pointless variable which will never be used, and this too seems to solve the problem :|

papillon68
10-19-2008, 09:44 PM
I'm experimenting this odd thing you pointed out: seems to me that the stack overflow is caused by the third vaue passed to the function. If you pass only two values (no matter what type are they) it actually works (no stack overflow shown).
So question is ... what's wrong with passing a third value to a function ?

wvxvw
10-19-2008, 10:15 PM
First, you shouldn't enclose return value within parenthesis i.e. return value; not return(value); Second, which is more probable, you have a setter with the name permission somewhere else in your code, so it is what causing recursion.

carn1x
10-20-2008, 05:44 AM
oh i did experiment with changing the variable "permission" or all sorts of different names to test this theory to no avail :(.

Well in the end it's all just my curiosity, as I'll end up jamming a ton of code in that function and the stack overflow should never happen. I just like to try and understand these things that's all!

Thanks for everyone's help anyway :)