Advertisement

Assert assigning from one dictionary to another

Started by November 03, 2014 07:30 PM
4 comments, last by iraxef 10 years ago

I'm trying to merge the contents of two dictionaries as follows:


dictionary d1 = {{'1','1'}};
dictionary d2 = {{'2','2'}};
array<string>@ keys = d2.getKeys();
for (uint i = 0; i < keys.length(); ++i)
{
    // Try 1:
    // No appropriate opAssign method found in 'dictionaryValue' for value assignment
    // Previous error occurred while attempting to create a temporary copy of object
    d1[keys[i]] = d2[keys[i]];

    // Try 2:
    // Assert "tempVariables.exists(offset)" at as_compiler.cpp:4895, asCCompiler::ReleaseTemporaryVariable()
    string key = keys[i];
    d1[key] = d2[key];
}

I would hope that approach 1 can work in the future, but approach 2 causes an assert with the following backtrace:


#7  0x09157dd3 in __assert_fail (__assertion=0x9607d55 "tempVariables.Exists(offset)", __file=0x96061b4 "AngelScript/source/as_compiler.cpp", __line=4895, __function=0x96094c0 "void asCCompiler::ReleaseTemporaryVariable(int, asCByteCode*)") at bld/Assert.cpp:46
#8  0x09108a30 in asCCompiler::ReleaseTemporaryVariable (this=0xbfbc3ad0, offset=14, bc=0x0) at AngelScript/source/as_compiler.cpp:4895
#9  0x091139ab in asCCompiler::CompileOverloadedDualOperator2 (this=0xbfbc3ad0, node=0xcc34154, methodName=0x95fde2f "opAssign", lctx=0xbfbc32c4, rctx=0xbfbc3368, ctx=0xbfbc3458, specificReturn=false, returnType=...) at AngelScript/source/as_compiler.cpp:11700
#10 0x09113f34 in asCCompiler::CompileOverloadedDualOperator (this=0xbfbc3ad0, node=0xcc34154, lctx=0xbfbc32c4, rctx=0xbfbc3368, ctx=0xbfbc3458, isHandle=false) at AngelScript/source/as_compiler.cpp:11602
#11 0x09105af0 in asCCompiler::DoAssignment (this=0xbfbc3ad0, ctx=0xbfbc3458, lctx=0xbfbc32c4, rctx=0xbfbc3368, lexpr=0xcc33e84, rexpr=0xcc34184, op=37, opNode=0xcc34154) at AngelScript/source/as_compiler.cpp:7504
#12 0x0911c7a7 in asCCompiler::CompileAssignment (this=0xbfbc3ad0, expr=0xcc33e54, ctx=0xbfbc3458) at AngelScript/source/as_compiler.cpp:7602
#13 0x0911d8d1 in asCCompiler::CompileExpressionStatement (this=0xbfbc3ad0, enode=0xcc33e24, bc=0xbfbc3590) at AngelScript/source/as_compiler.cpp:4309
#14 0x0912bd36 in asCCompiler::CompileStatementBlock (this=0xbfbc3ad0, block=0xcc25d64, ownVariableScope=true, hasReturn=0xbfbc3687, bc=0xbfbc37e0) at AngelScript/source/as_compiler.cpp:1121
#15 0x09129e54 in asCCompiler::CompileStatement (this=0xbfbc3ad0, statement=0xcc25d64, hasReturn=0xbfbc3687, bc=0xbfbc37e0) at AngelScript/source/as_compiler.cpp:3515
#16 0x0912ad69 in asCCompiler::CompileForStatement (this=0xbfbc3ad0, fnode=0xcc25674, bc=0xbfbc38b0) at AngelScript/source/as_compiler.cpp:4068
#17 0x0912bd36 in asCCompiler::CompileStatementBlock (this=0xbfbc3ad0, block=0xb47efdc, ownVariableScope=false, hasReturn=0xbfbc397f, bc=0xbfbc3980) at AngelScript/source/as_compiler.cpp:1121
#18 0x0912c0b3 in asCCompiler::CompileFunction (this=0xbfbc3ad0, builder=0xcc21d4c, script=0xcc31c54, parameterNames=..., func=0xb4c02bc, outFunc=0xcc20f9c, classDecl=0x0) at AngelScript/source/as_compiler.cpp:553
#19 0x090d7917 in asCBuilder::CompileFunctions (this=0xcc21d4c) at AngelScript/source/as_builder.cpp:835
#20 0x090e9f36 in asCBuilder::Build (this=0xcc21d4c) at AngelScript/source/as_builder.cpp:244

Am I doing anything wrong with the above syntax?

32-bit linux, rev 2030

Thank you!

No, you aren't doing anything wrong.

The first scenario is failing because the dictionaryValue type registered by the CScriptDictionary add-on doesn't have a method with signature 'dictionaryValue &opAssign(const dictionaryValue &in)', nor does it have a copy constructor for creating a temporary copy to safely call the existing 'dictionary &opAssign(const ?&in)' method.

The second scenario is failing due to some bug in the compiler that I still need to investigate.

I'll have both of the scenarios fixed as soon as I can.

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

Both problems have been fixed in revision 2040.

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 change appears to have broken the ability to store a funcdef in a dictionary:


funcdef void CB();

void test()
{
    print("in test");
}

void main()
{
    test(); // works

    CB@ func = @test;
    func(); // works

    dictionary dict;
    @dict['func'] = func;

    if ( dict.exists('func') )
        print("exists"); // prints "exists"

    CB@ func2 = cast<CB>(dict['func']);
    if ( func2 is null )
        print("Why am I null?"); // this prints

    func2(); // "Unbound function called" exception
}

The problem was introduced when I changed the dictionary to use the new RefCastObject to convert the stored handle to the desired type. RefCastObject doesn't work for function pointers since they require the asIScriptFunction pointer too in order to have the full view of the function signature.

I've fixed this now in revision 2051.

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

Fix confirmed - thank you!!

This topic is closed to new replies.

Advertisement