0

I am using as3-signals-v0.9-BETA in a simple slide application. In my signal handler, I am dispatching the same signal again based on some conditions.

The application throws an exception after a couple of hours on the signals dispatch method. Below is a stack trace:

Error:

Error #1023: Stack overflow occurred.
     at com.chetansachdev.components::SlideDeck/onNextSlidePleaseEvent()[D:\cb-trunk\Solutions\Components\Slidelib\src\com\chetansachdev\components\SlideDeck.as:75]
     at org.osflash.signals::Slot/execute()[C:\Users\Robert\Documents\Flash\OSFlash\signals\as3-signals\src\org\osflash\signals\Slot.as:87]
     at org.osflash.signals::OnceSignal/dispatch()[C:\Users\Robert\Documents\Flash\OSFlash\signals\as3-signals\src\org\osflash\signals\OnceSignal.as:125]
     at com.chetansachdev.components::SlideDeck/onNextSlidePleaseEvent()[D:\cb-trunk\Solutions\Components\Slidelib\src\com\chetansachdev\components\SlideDeck.as:89]
     at org.osflash.signals::Slot/execute()[C:\Users\Robert\Documents\Flash\OSFlash\signals\as3-signals\src\org\osflash\signals\Slot.as:87]
     at org.osflash.signals::OnceSignal/dispatch()[C:\Users\Robert\Documents\Flash\OSFlash\signals\as3-signals\src\org\osflash\signals\OnceSignal.as:125]
     ...
     ...

Method:

mysignal.add(mySignalHandler);

function mySignalHandler():void
{
    if(condition)
    {
       // do something here..
    }
    else
    {
        mysignal.dispatch();
    }
}

Can some one point me, what is wrong. When I am dispatching from the signal handler, is the stack getting created? (I am not calling the method directly, I am dispatching a signal).

Arkana
  • 2,831
  • 20
  • 35
Chetan Sachdev
  • 738
  • 1
  • 12
  • 31

1 Answers1

0

It's an infinite loop. It's like writing this:

function inifityAndBeyond(){
    infinityAndBeyond();
}

In other words it doesn't make sense to dispatch the same signal in the handler of the signal.

Creynders
  • 4,573
  • 20
  • 21
  • Thx for your reply. I am not calling the method directly from the handler. I am dispatching an event/signal, so I don't think it is an infinite loop. If I put a trace statement before the end of the method, that gets executed. – Chetan Sachdev Apr 18 '13 at 13:27
  • Then you'll need to update your code in your question to better represent the situation. As it is now, it _is_ the same as calling the same method recursively. There's no automatic async delaying in signals. – Creynders Apr 18 '13 at 15:20
  • Makes sense. I tried calling another method and removing all signals and adding the listener only once. I still get the exception, after few hours. I am going to implement it in another way, where I don't have to call the same method again. Thanks for your answer :) – Chetan Sachdev Apr 19 '13 at 08:01