Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a runtime stack underflow error?

I'm really struggling to resolve a stack underflow that I'm getting. The traceback I get at runtime is:

VerifyError: Error #1024: Stack underflow occurred.

at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

This is particularly difficult to debug because when I run in debug mode it does not happen at all. It only happens when compiled as a release.

Does anyone have any tips on how to debug a Stack Underflow? Are have a clean explanation of what that means for Flash?

In case it helps, this error is occurring when I click a button whose handler makes an RPC call, which uses a URLLoader, an AsyncToken, and then invokes the set of AsyncResponder instances associated with the AsyncToken. With some server-side logging as well as some logging hacked into the swf, I know that the UrlLoader is successfully doing and GET'ing a crossdomain.xml file, is correctly processing it (ie: if I wreck it, I get a security error), and is also successfully completing the "load" request (the server sends the data). The underflow seems to be happening in the Event.COMPLETE listening/handling process (as is, of course, implied by the traceback as well).

mxmlc used = from flex_sdk_4.5.0.20967

Example player (I've tried a few) = 10.2.153.1


UPDATE: My specific problem is solved... but I'm leaving the question as-is since I would like to know how to generally debug such a problem, rather than just getting my specific solution.

In my code I had the following Application definition:

<s:Application height="100%" width="100%"
                              xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               initialize="InitData();">

Note that the code is/was attached to the initialize event.

InitData() and relevant defintions are/were:

import classes.RpcServerProxy;
public var SP:RpcServerProxy;

public function InitData():void {
    SP = new RpcServerProxy("http://192.168.1.102:1234");
}

When I switched the InitData() call to be on the onCompletion event instead of initialize (thanks J_A_X!), the problem goes away entirely. What seems to have been happening was that the Event.COMPLETE event handler (onComplete in the stack trace) was using the global SP object. Something about the release (vs debug) compilation must have been affecting the startup timing of the SP variable initialization. Moving the handler later to the onCompletion event resolved all issues.

As said above, I would still like to know what tricks/tools are available for debugging initialization issues like this.


UPDATE 2:

applicationComplete seems to be an even better event than creationComplete to put application initialization code. See this blog entry for some explanation, and and this video (around 4:25) by an Adobe Tech Evangelist for an example of simple "start of application" data initialization.

like image 438
Russ Avatar asked Jun 07 '11 19:06

Russ


People also ask

What is stack underflow error?

An error condition that occurs when an item is called for from the stack, but the stack is empty.

What causes stack underflow?

Stack Underflow & Overflow Stack underflow happens when we try to pop (remove) an item from the stack, when nothing is actually there to remove. This will raise an alarm of sorts in the computer because we told it to do something that cannot be done.

Is stack overflow error a runtime error?

A stack overflow is a runtime error that happens when a program runs out of memory in the call stack. The stack overflow generally signals a problem in resource provisioning and has to be fixed in order to allow the program to run and use memory properly.

How stack limit is used to check for stack overflow full stack or underflow empty stack?

The underflow condition checks if there exists any item before popping from the stack. An empty one cannot be popped further. The overflow condition checks if the stack is full (or more memory is available) before pushing any element. This prevents any error if more space cannot be allocated for the next item.


1 Answers

I got rid of this error by adding compiler argument:
-omit-trace-statements=false

like image 84
Andrei Avatar answered Oct 05 '22 07:10

Andrei