Advertisement

Crash when instantiating handle with weird syntax

Started by July 25, 2014 06:02 PM
1 comment, last by WitchLord 10 years, 3 months ago

array<string> foo = { 'a', 'b', 'c' };
dictionary d1 = { {'arr', foo} };

array<string>@ s1 = array<string>@(d1['arr']);
//print(s1[0]); // index out of bounds exception

dictionary@ d2 = @d1;
array<string>@ s2 = array<string>@(d2['arr']); <-- segfaults with the below backtrace:


(gdb) bt
#0  0x005ee375 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#1  0x090ac582 in endcopy8 () at AngelScript/source/as_callfunc_x86.cpp:515
#2  0x090acdee in CallSystemFunctionNative (context=0xd4c1a04, descr=0xac563b4, obj=0xd4ef560, args=<optimized out>, retPointer=0x0) at AngelScript/source/as_callfunc_x86.cpp:262
#3  0x090abf20 in CallSystemFunction (id=59, context=0xd4c1a04, objectPointer=0x0) at AngelScript/source/as_callfunc.cpp:604
#4  0x09069251 in asCContext::ExecuteNext (this=0xd4c1a04) at AngelScript/source/as_context.cpp:2404
#5  0x09069d10 in asCContext::Execute (this=0xd4c1a04) at AngelScript/source/as_context.cpp:1227

This is 32-bit linux on revision 1985 (Version 2.29.2 WIP - 2014/07/21)

Is there anything 'wrong' with the above syntax (beyond being a weird way to do it)? Anything that might be done to make it a compiler error or a runtime exception?

Thank you!

The syntax is definitely wrong. I have no idea what the compiler decided to do with this syntax. It should have given a compilation error.

I'll need to look into this.

array<string> foo = { 'a', 'b', 'c' };
dictionary d1 = { {'arr', foo} };  //  this syntax should make a copy of the array and store it in the dictionary under the key 'arr'
// dictionary d1 = { {'arr', @foo} }; // this syntax on the other hand would keep a reference (handle) to the original array 

// array<string>@ s1 = array<string>@(d1['arr']); // This syntax is invalid. The @ symbol in the right expression is in the wrong place
array<string>@ s1 = cast<array<string>>(d1['arr']); // This syntax would cast the returned reference from d1['arr'] to the array<string> type you want

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 1991.

The compiler will no longer accept the invalid syntax array<string>@(d1['arr']);

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