Advertisement

build a script containing array-of-string failed with corrupted VM stack

Started by May 08, 2021 05:34 AM
2 comments, last by WitchLord 3 years, 6 months ago

When I compile the script below, it failed an assertion with a stack size of -2, at the last line of CByteCode::DebugOutput function.

void main() {
    array<int> a = {1, 2, 3};
    console_log( "a length: "+string(a.length()) );
    console_log( "a[0]: "+string(a[0]) );
    console_log( "a[1]: "+string(a[1]) );
    console_log( "a[2]: "+string(a[2]) );
    a[1] = 666;
    console_log( "a[1] modified: "+string(a[1]) );
    array<string> b = {"foo", "bar", "baz"};
}

Actually, the build stage fails even if I delete other lines in main() function and only keep the last line declaring the array-of-string. To the contrary, if I delete the last line whilst keeping other lines for the array-of-int operations, the script compiles and runs successfully .

The array type used is the one shipped with AngelScript source code pack. I forced it to use GENERIC function binding for maximum compatibility.

The string type used is a binding to memory-pooled std::string, and it has been briefly tested in another program which looks good.

I run the script with AS_DEBUG and it gives the following output in __main.txt:

void main()

Temps: 4, 5, 15, 25, 35, 36, 40

Variables: 
 002: (heap) int[] a
 038: (heap) string[] b
 004: (heap)  {noname}
 040: (heap)  {noname}
 015: string {noname}
 025: string {noname}
 035: string {noname}


- 2,5 -
    0  40 *    SUSPEND
               VarDecl  0
    1  40 *    AllocMem v4, 16
    3  40 *    SetListSize v4, 0, 3
    6  40 *    SetV4    v5, 0x1          (i:1, f:1.4013e-45)
    8  40 *    PshListElmnt v4, 4
   10  42 *    PopRPtr
   11  40 *    WRTV4    v5
   12  40 *    SetV4    v5, 0x2          (i:2, f:2.8026e-45)
   14  40 *    PshListElmnt v4, 8
   16  42 *    PopRPtr
   17  40 *    WRTV4    v5
   18  40 *    SetV4    v5, 0x3          (i:3, f:4.2039e-45)
   20  40 *    PshListElmnt v4, 12
   22  42 *    PopRPtr
   23  40 *    WRTV4    v5
   24  40 *    PshVPtr  v4
   25  42 *    CALL     85           (int[]@ $list(int&in) { repeat int })
   27  40 *    STOREOBJ v2
   28  40 *    FREE     v4, 0x4aae0228          (type:)
- 3,5 -
   31  40 *    SUSPEND
   32  40 *    PGA      0x4aae0438          (str:a length: )
   35  42 *    PSF      v25
   36  44 *    CALLSYS  20           (string::string(const string&in))
               ObjInfo  v25, 1
   38  40 *    PshVPtr  v2
   39  42 *    CALLSYS  95           (uint array::length() const)
   41  40 *    CpyRtoV4 v5
   42  40 *    PshV4    v5
   43  41 *    PSF      v15
   44  43 *    CALLSYS  22           (string::string(uint))
               ObjInfo  v15, 1
   46  40 *    VAR      v15
   47  42 *    PSF      v35
   48  44 *    PSF      v25
   49  46 *    GETREF   4
   50  46 *    CALLSYS  35           (string string::opAdd(const string&in) const)
               ObjInfo  v35, 1
   52  40 *    PSF      v25
   53  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v25, 0
   55  40 *    PSF      v15
   56  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v15, 0
   58  40 *    PSF      v35
   59  42 *    CALLSYS  39           (void console_log(const string&in))
   61  40 *    PSF      v35
   62  42 *    CALLSYS  27           (string::~string())
- 4,5 -
               ObjInfo  v35, 0
   64  40 *    SUSPEND
   65  40 *    PGA      0x4aae0cd8          (str:a[0]: )
   68  42 *    PSF      v15
   69  44 *    CALLSYS  20           (string::string(const string&in))
               ObjInfo  v15, 1
   71  40 *    PshC4    0x0          (i:0, f:0)
   73  41 *    PshVPtr  v2
   74  43 *    Thiscall1 86           (int& array::opIndex(uint))
   76  40 *    RDR4     v5
   77  40 *    PshV4    v5
   78  41 *    PSF      v35
   79  43 *    CALLSYS  21           (string::string(int))
               ObjInfo  v35, 1
   81  40 *    VAR      v35
   82  42 *    PSF      v25
   83  44 *    PSF      v15
   84  46 *    GETREF   4
   85  46 *    CALLSYS  35           (string string::opAdd(const string&in) const)
               ObjInfo  v25, 1
   87  40 *    PSF      v15
   88  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v15, 0
   90  40 *    PSF      v35
   91  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v35, 0
   93  40 *    PSF      v25
   94  42 *    CALLSYS  39           (void console_log(const string&in))
   96  40 *    PSF      v25
   97  42 *    CALLSYS  27           (string::~string())
- 5,5 -
               ObjInfo  v25, 0
   99  40 *    SUSPEND
  100  40 *    PGA      0x4aae1bc8          (str:a[1]: )
  103  42 *    PSF      v35
  104  44 *    CALLSYS  20           (string::string(const string&in))
               ObjInfo  v35, 1
  106  40 *    PshC4    0x1          (i:1, f:1.4013e-45)
  108  41 *    PshVPtr  v2
  109  43 *    Thiscall1 86           (int& array::opIndex(uint))
  111  40 *    RDR4     v5
  112  40 *    PshV4    v5
  113  41 *    PSF      v25
  114  43 *    CALLSYS  21           (string::string(int))
               ObjInfo  v25, 1
  116  40 *    VAR      v25
  117  42 *    PSF      v15
  118  44 *    PSF      v35
  119  46 *    GETREF   4
  120  46 *    CALLSYS  35           (string string::opAdd(const string&in) const)
               ObjInfo  v15, 1
  122  40 *    PSF      v35
  123  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v35, 0
  125  40 *    PSF      v25
  126  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v25, 0
  128  40 *    PSF      v15
  129  42 *    CALLSYS  39           (void console_log(const string&in))
  131  40 *    PSF      v15
  132  42 *    CALLSYS  27           (string::~string())
- 6,5 -
               ObjInfo  v15, 0
  134  40 *    SUSPEND
  135  40 *    PGA      0x4aae1e60          (str:a[2]: )
  138  42 *    PSF      v25
  139  44 *    CALLSYS  20           (string::string(const string&in))
               ObjInfo  v25, 1
  141  40 *    PshC4    0x2          (i:2, f:2.8026e-45)
  143  41 *    PshVPtr  v2
  144  43 *    Thiscall1 86           (int& array::opIndex(uint))
  146  40 *    RDR4     v5
  147  40 *    PshV4    v5
  148  41 *    PSF      v15
  149  43 *    CALLSYS  21           (string::string(int))
               ObjInfo  v15, 1
  151  40 *    VAR      v15
  152  42 *    PSF      v35
  153  44 *    PSF      v25
  154  46 *    GETREF   4
  155  46 *    CALLSYS  35           (string string::opAdd(const string&in) const)
               ObjInfo  v35, 1
  157  40 *    PSF      v25
  158  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v25, 0
  160  40 *    PSF      v15
  161  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v15, 0
  163  40 *    PSF      v35
  164  42 *    CALLSYS  39           (void console_log(const string&in))
  166  40 *    PSF      v35
  167  42 *    CALLSYS  27           (string::~string())
- 7,5 -
               ObjInfo  v35, 0
  169  40 *    SUSPEND
  170  40 *    SetV4    v36, 0x29a          (i:666, f:9.33265e-43)
  172  40 *    PshC4    0x1          (i:1, f:1.4013e-45)
  174  41 *    PshVPtr  v2
  175  43 *    Thiscall1 86           (int& array::opIndex(uint))
  177  40 *    WRTV4    v36
- 8,5 -
  178  40 *    SUSPEND
  179  40 *    PGA      0x4aae2928          (str:a[1] modified: )
  182  42 *    PSF      v25
  183  44 *    CALLSYS  20           (string::string(const string&in))
               ObjInfo  v25, 1
  185  40 *    PshC4    0x1          (i:1, f:1.4013e-45)
  187  41 *    PshVPtr  v2
  188  43 *    Thiscall1 86           (int& array::opIndex(uint))
  190  40 *    RDR4     v5
  191  40 *    PshV4    v5
  192  41 *    PSF      v35
  193  43 *    CALLSYS  21           (string::string(int))
               ObjInfo  v35, 1
  195  40 *    VAR      v35
  196  42 *    PSF      v15
  197  44 *    PSF      v25
  198  46 *    GETREF   4
  199  46 *    CALLSYS  35           (string string::opAdd(const string&in) const)
               ObjInfo  v15, 1
  201  40 *    PSF      v25
  202  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v25, 0
  204  40 *    PSF      v35
  205  42 *    CALLSYS  27           (string::~string())
               ObjInfo  v35, 0
  207  40 *    PSF      v15
  208  42 *    CALLSYS  39           (void console_log(const string&in))
  210  40 *    PSF      v15
  211  42 *    CALLSYS  27           (string::~string())
- 9,5 -
               ObjInfo  v15, 0
  213  40 *    SUSPEND
               VarDecl  1
  214  40 *    AllocMem v40, 124
  216  40 *    SetListSize v40, 0, 3
  219  40 *    PshListElmnt v40, 4
  221  42 *    CALLSYS  19           (string::string())
  223  40 *    PGA      0x4aae1588          (str:foo)
  226  42 *    PshListElmnt v40, 4
  228  44 *    CALLSYS  29           (void string::opAssign(const string&in))
  230  40 *    PopPtr
  231  38 *    PshListElmnt v40, 44
  233  40 *    CALLSYS  19           (string::string())
  235  38 *    PGA      0x4aae9990          (str:bar)
  238  40 *    PshListElmnt v40, 44
  240  42 *    CALLSYS  29           (void string::opAssign(const string&in))
  242  38 *    PopPtr
  243  36 *    PshListElmnt v40, 84
  245  38 *    CALLSYS  19           (string::string())
  247  36 *    PGA      0x4aae9be8          (str:baz)
  250  38 *    PshListElmnt v40, 84
  252  40 *    CALLSYS  29           (void string::opAssign(const string&in))
  254  36 *    PopPtr
  255  34 *    PshVPtr  v40
  256  36 *    CALL     117           (string[]@ $list(int&in) { repeat string })
  258  34 *    STOREOBJ v38
  259  34 *    FREE     v40, 0x4aae94b0          (type:)
- 10,2 -
  262  34 *    SUSPEND
  263  34 *    FREE     v38, 0x4aae0a48          (type:array)
  266  34 *    FREE     v2, 0x4aadb5a0          (type:array)
            0:
  269  34 *    RET      0

I'll need to investigate this in more detail. But looking at the debug output it seems the problem is related to the fact that your string::opAssign method returns ‘void’ instead of a reference to the string.

Of course, this is certainly a bug in AngelScript, but I think you can work around it by updating your opAssign method to return the reference to the string.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I've fixed this in revision 2732.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement