9 Replies Latest reply on Feb 10, 2010 2:01 AM by Harry Kunz

    Overflow stack bug

    Holoville
      Hello,

      I found this strange bug while coding, and wrote it in the simplest way to be sure it was true. Try opening a new AS3 FLA file, and write this code in the Actions Panel:


      function someFunc(x1:String, x2:String, x3:Number=0):String
      {
      var my_result:String = "result";
      return my_result;
      }
      someFunc("someVal1", "someVal2");


      Calling someFunc will call a #1023 stack overflow error!!! The only way not to have it is to remove the "x3" Parameter. That's sooooooo strange (and annoying, 'cause before realizing this was a bug i was getting crazy trying to find an error in my original code, which was much more complex).

      P.S. i'm using FlashPlayer debugging version 9.0.r47, i hope it's his fault - or maybe there's another reason? Any idea?

      Daniel

        • 1. Re: Overflow stack bug
          clbeech Level 3
          Hey man, I don't know much about CS3 yet, but as far as I know (and I tried this in AS2) you can't assign a value to a parameter in the function definition. (eg. ... x3:Number=0)

          try pulling that and see if it works.
          • 2. Re: Overflow stack bug
            Damon Edwards Level 3
            no, you can not..
            function someFunc(x1:String, x2:String, x3:Number):String

            "this was a bug"
            Not a bug, but user error.
            • 3. Re: Overflow stack bug
              Holoville Level 1
              Hey guys,

              one of the nice things in AS3 is exactly that you can assign default values (parX="something") to functions parameters. While on the contrary, you always have to pass the right number of parameters when calling a function, unless some of those are defaults. You can check the manual if you don't trust me :-P ("default parameter values").

              Given that, we're back to the original problem... not a user error, but a bug :-) (And by the way, the bug happens even if none of someFunc parameters are set as defaults)

              Cheers
              • 4. Re: Overflow stack bug
                Holoville Level 1
                P.S. this is the output error code generated by that code. I'm posting it because it's so different from other error outputs, and by what it says it really seems that Flash is going crazy. When you see "stackOverflow_01_fla", that's the name of the AS3 FLA i created (stackOverflow_01.FLA) to debug this error.


                verify stackOverflow_01_fla::MainTimeline/someFunc()
                stack:
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$]
                locals: stackOverflow_01_fla::MainTimeline String? String? Number *
                0:getlocal0
                stack: stackOverflow_01_fla::MainTimeline
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$]
                locals: stackOverflow_01_fla::MainTimeline String? String? Number *
                1:pushscope
                stack:
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$] stackOverflow_01_fla::MainTimeline
                locals: stackOverflow_01_fla::MainTimeline String? String? Number *
                2:pushnull
                stack: null
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$] stackOverflow_01_fla::MainTimeline
                locals: stackOverflow_01_fla::MainTimeline String? String? Number *
                3:coerce_s
                stack: String?
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$] stackOverflow_01_fla::MainTimeline
                locals: stackOverflow_01_fla::MainTimeline String? String? Number *
                4:setlocal 4
                stack:
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$] stackOverflow_01_fla::MainTimeline
                locals: stackOverflow_01_fla::MainTimeline String? String? Number String?
                6:pushstring "result"
                stack: String
                scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ stackOverflow_01_fla::MainTimeline$] stackOverflow_01_fla::MainTimeline
                locals: stackOverflow_01_fla::MainTimeline String? String? Number String?
                8:dup
                VerifyError: Error #1023: Stack overflow occurred.
                at stackOverflow_01_fla::MainTimeline/someFunc()
                at stackOverflow_01_fla::MainTimeline/stackOverflow_01_fla::frame1()

                • 5. Re: Overflow stack bug
                  clbeech Level 3
                  quote: "While on the contrary, you always have to pass the right number of parameters when calling a function"
                  ----------

                  OK (rem, know nothing of AS3), if this is true, then you should pass a value in the call right? because you have ...
                  --------
                  someFunc("someVal1", "someVal2");
                  • 6. Overflow stack bug
                    Holoville Level 1
                    Nope :-) (hey, I really appreciate the effort though, thanks :-) )

                    You have to pass only the right number of non-default parameters. Thus in that function you're obliged to pass the first 2 parameters, but not the 3rd, which, having a default value, is optional (sorry if i was a little confusional).

                    Anyway, error #1023 happens even if you pass the third parameter. One way of not having error #1023 happen is writing something else inside the function. Obviously you'll always write something else in there (it would be useless not to), but this doesn't mean it's not a bug :-)

                    I find it quite annoying because often, when writing a Class with a series of static functions, first i write the empty functions (thus i know what i have to pass and to return), and only afterwards i fill them with code.

                    Example:

                    THIS CAUSES THE ERROR


                    function someFunc(x1:String, x2:String, x3:Number=0):String
                    {
                    var my_result:String = "result";
                    return my_result;
                    }
                    someFunc("someVal1", "someVal2");



                    THIS DOESNT CAUSE ANY ERROR


                    function someFunc(x1:String, x2:String, x3:Number=0):String
                    {
                    var my_result:String = "result";
                    var casualVar:Number = 1;
                    return my_result;
                    }
                    someFunc("someVal1", "someVal2");


                    Daniel
                    • 7. Re: Overflow stack bug
                      wendy888 Level 1

                        Holoville

                          Just started to learn Flex and I got the same error even I did not pass any parameters. Do you get resolved this problem?

                          Any new in this issue can be shared?

                       

                      Thank you in advance!

                      • 8. Re: Overflow stack bug
                        ianryaninteractive12345

                        Today is Feb 8, 2010

                         

                         

                        I just came across this weird bug, is this still an unresolved issue?

                         

                        *make a movieclip called scrollbar, inside that mc, make two other movieclips, name them the bg(scrollbar area) and slider (scrollbar slider)

                        then make another on the same level and just call it contentHolder

                         

                        //VerifyError: Error #1023: Stack overflow occurred.

                        function makeScrollBar(scrollBarMov:MovieClip, scrollBarHeight:Number, contentMov) {
                            var sb:MovieClip=scrollBarMov;


                            var sb_scroller:MovieClip=sb.scroller;
                            var sb_bg:MovieClip=sb.bg;


                            var contentmov:MovieClip = contentMov;


                            //sb_scroller.max = 0;

                         

                            return sb;
                        }

                         

                        now just simply call the function

                         

                        var newScrollbar:MovieClip = makeScrollBar(this.scrollbar, 100, contentHolder);

                         

                         

                        the workaround is strange, but it's fixed by removing the comment lines to give the scroller a new variable

                         

                        This inconsitancy is making me worry..why haven't I, out of 10 years of doing this stuff have come across this bug until now?

                        • 9. Re: Overflow stack bug
                          Harry Kunz Level 4

                          The variable x3 is unused so it causes that weird error. Place a statement inside that function that will use x3 and the error goes away. You can place trace(x3) and the error goes away. Why even create function parameters that you are not using.