Results 1 to 9 of 9

Thread: EmptyStackException when using call

  1. #1
    Senior Member
    Join Date
    Nov 2007
    Posts
    225

    Default EmptyStackException when using call

    The code below is just about as trival an example as I could come up with, but it seems that perhaps some variables are not getting scoped correctly when using the call command?
    Code:
    int funcB(int[String] l)
    {
        print("Start B");
        int[String] m;
        m["funcC"]=1;
        int[int] r;
        int i=0;
        foreach v in l
        {
            i+=1;
            r[i]=call int v(m);
        }
        print("End B");
        return 1;
    }
    
    
    int funcC(int[String] l)
    {
        print("Start C "+l.Count());
        foreach v in l
        {
            print(v);
        }
        print("End C");
        return 5;
        
    }
    
    
    void main()
    {
        int[String] list;
        list["funcB"]=1;
        Print("Start");
        funcB(list);
        print("Done");
    }
    Shows Output:
    Start
    Start B
    Start B
    Start C 1
    funcC
    End C
    End B
    Unexpected error, debug log printed.
    Script execution aborted
    Stack Trace attached. EmptyStackException
    Attached Files

  2. #2
    Developer roippi's Avatar
    Join Date
    Aug 2010
    Posts
    2,663

    Default

    Thread title changed to something useful.

  3. #3
    Senior Member
    Join Date
    Jul 2007
    Posts
    1,193

    Default

    There's a lot of noise in the example, can be condensed to:
    Code:
    void funcB(string myFunc) {
        call void myFunc("funcC");
    }
    
    void funcC(string i) {}
    
    void main() {
        funcB("funcB");
    }

  4. #4
    Senior Member
    Join Date
    Nov 2007
    Posts
    225

    Default

    Is there any hope for this one getting fixed? I downloaded the latest code via SVN, and installed eclipse to try to take a look at it myself, but I am a C# Dev, not really a java guy... maybe someone can give me some advice of what I am looking for? I got to the point where I was able to write to the console all the trace output for the function calls... but I couldn't find where the Call logic was.

  5. #5
    Senior Member
    Join Date
    Jul 2007
    Posts
    1,193

    Default

    From memory, I think the call logic is in FunctionCall.java? Most ASH functions tend to have their own class in parsetree. I remember looking at this briefly and I don't think the problem is in FunctionCall.java but it might be. I might look at it later but I have a lot on my plate atm.
    Procrastination
    Leaves many things unfinished

    Originally Posted by /haiku

  6. #6
    Senior Member
    Join Date
    Nov 2007
    Posts
    225

    Default

    Ok... so the empty stack exception was coming from restoreBindings in UserDefinedFunction.java

    So I made 2 changes to the func
    Code:
    ArrayList values=(ArrayList) this.callStack.pop();
    .
    .
    if(!current.isStatic())
    {
     current.forceValue((Value) values.get(i++));
    }
    became
    Code:
    ArrayList values = null;
    if (!this.callStack.isEmpty())
    {
       values = (ArrayList) this.callStack.pop();
    }
    .
    .
    .
    if (!current.isStatic() && !(values ==null))
    {
      current.forceValue((Value)values.get(i++));
    }
    I was worried that there might be some side effect, such as a Return value getting ignored, but changing your test script to:
    Code:
    int funcB(string myFunc){
      int c= call void myFunc("funcC");
      return c+1;
    }
    
    int funcC(string i){return 1;}
    
    void main(){
       print(funcB("funcB"));
    }

    has the desired output of 3.

    Note: I don't know if this is the "Correct" fix, of if it is just a hammer it until it fits fix.
    Last edited by Paragon; 02-09-2013 at 01:48 AM.

  7. #7
    Senior Member
    Join Date
    Jul 2007
    Posts
    1,193

    Default

    I don't think the callstack should be empty in the first place, so you're kinda patching the symptoms instead of the cause. Perhaps I am mistaken, though.

    If your changes to the test script worked than that would be a bug in itself, particularly this line int c= call void myFunc("funcC"); as void funcB and void funcC don't exist.

  8. #8
    Senior Member
    Join Date
    Nov 2007
    Posts
    225

    Default

    Double checked, you are correct... I typo'ed the change and it does in fact have to call int myFunc rather then call void myFunc.

    Here is trace... Note the line that I marked... perhaps that is a clue as to what is happening.
    Code:
    Executing main function
          Param #1: funcB()
             Param #1: "funcB"
             [NORMAL] <- "funcB"
             Entering function funcB
                   Eval: call int myFunc()
                      Invoke: call int myFunc()
                      Function name: myFunc
                      [NORMAL] <- funcB
                         Param #1: "funcC"
                         [NORMAL] <- "funcC"
                         Entering function funcB
                               Eval: call int myFunc()
                                  Invoke: call int myFunc()
                                  Function name: myFunc
                                  [NORMAL] <- funcC
                                     Param #1: "funcC"
                                     [NORMAL] <- "funcC"
                                     Entering function funcC
                                           Eval: 1
                                           Returning: 1
                                        [RETURN] <- 1
                                     Function funcC returned: 1
                               Set: 1
                            [NORMAL] <- 1
                               Eval: ( c + 1 )
                                  Operator: +
                                     Operand 1: c
                                     [NORMAL] <- 1
                                     Operand 2: 1
                                     [NORMAL] <- 1
                                  <- 2
                               Returning: 2
                            [RETURN] <- 2
                         Function funcC returned: 2     <--- ODD Shouldn't this say funcB returned 2?  (This is also the line where execution is aborted in current version
                   Set: 2
                [NORMAL] <- 2
                   Eval: ( c + 1 )
                      Operator: +
                         Operand 1: c
                         [NORMAL] <- 2
                         Operand 2: 1
                         [NORMAL] <- 1
                      <- 3
                   Returning: 3
                [RETURN] <- 3
             Function funcB returned: 3
          [NORMAL] <- 3
          Entering function print
          Function print returned: void
       [NORMAL] <- void
    Sorry if I am stepping on toes, It's just a feature that a script that I am creating requires and I'm trying to help solve it, but I am a real fish out of water in java and this is some pretty confusing sections of code.
    Last edited by Paragon; 02-09-2013 at 03:59 AM.

  9. #9
    Developer
    Join Date
    Aug 2009
    Posts
    2,688

    Default

    Probably fixed at some point, since the example in the first post runs to completion without generating any errors.

Similar Threads

  1. Replies: 1
    Last Post: 01-17-2012, 09:14 PM
  2. Feature - Rejected call script parameters
    By bordemstirs in forum Bug Reports
    Replies: 2
    Last Post: 10-19-2010, 03:55 AM
  3. Call a macro. How to do it?
    By tripwood in forum Community Support
    Replies: 3
    Last Post: 03-23-2009, 09:09 PM
  4. How do I call a .ccs from the CLI?
    By Kajomboman in forum Custom Combat Settings
    Replies: 1
    Last Post: 06-26-2008, 03:11 PM
  5. Call external URLs?
    By muffins in forum Scripting Discussion
    Replies: 2
    Last Post: 05-19-2006, 08:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •