Bug with @&

Started by
5 comments, last by WitchLord 11 years, 11 months ago
Hello smile.png

C++


node type is - asRef

r=en->RegisterObjectMethod("Object","Node &FirstNode()", asMETHOD( Object, FirstNode ), asCALL_THISCALL ); assert( r >= 0 );

r=en->RegisterObjectMethod("Xml","void SetNode(Node@&)", asMETHOD(Xml,SetNode),asCALL_THISCALL);assert(r>=0);





This script code work!

Node @n = cam.FirstNode();

xml.GetNode( n );



But, This code crash program!




xml.GetNode( cam.FirstNode() );


Reference no valid!
Advertisement
Is it GetNode() or SetNode()?

You're using asEP_ALLOW_UNSAFE_REFERENCES, right? Otherwise @& shouldn't be allowed. Without unsafe references it must be either @&in or @&out.

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


Is it GetNode() or SetNode()?


Sorry, need go sleep!wacko.png yes i use asEP_ALLOW_UNSAFE_REFERENCES

Create example:


struct TestLink
{
TestLink(){ val = 123; }
int val;
};
TestLink *GetTestLink()
{
return new TestLink();
}


r=en->RegisterObjectType( "TestLink", 0, asOBJ_REF | asOBJ_NOCOUNT ); assert( r >= 0 );
r=en->RegisterObjectProperty( "TestLink", "int val", asOFFSET( TestLink, val ) ); assert( r >= 0 );
r=en->RegisterGlobalFunction("TestLink &GetTestLink()", asFUNCTION(GetTestLink), asCALL_CDECL); assert( r >= 0 );


Script:



void PrintLink_1( TestLink @ t )
{
print( "1 TestLink.val: " + t.val +"\n" );
}

void PrintLink_2( TestLink @&in t )
{
print( "2 TestLink.val: " + t.val +"\n" );
PrintLink_3( t );
}

void PrintLink_3( TestLink @& t )
{
print( "3 TestLink.val: " + t.val +"\n" );
}

void PrintLink_4( TestLink @& t )
{
print( "4 TestLink.val: " + t.val +"\n" );
}

void startGame( string &param )
{
PrintLink_1( GetTestLink() );
PrintLink_2( GetTestLink() );
PrintLink_4( GetTestLink() );

}


1 TestLink.val: 123
2 TestLink.val: 123
3 TestLink.val: 123
PrintLink_4 - crash program

as_context.cpp[ 2522 ]


case asBC_RDR4:
*(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD**)&regs.valueRegister;
l_bc++;
break;
I've fixed this bug in revision 1302.

Observe, that the compiler will now give an error @& if the argument expression is not an object handle, which is your case.

As @& means that the function should be allow to modify the handle itself, the argument expression must be a modifiable handle.

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

PrintLink_4( GetTestLink() );

this code no compilate - greate!smile.png

but this compilate and crash!

PrintLink_4( cast<TestLink@>( GetTestLink() ) );
Thanks.

Looks like a slightly different scenario. I'll have a look at it.

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

I've fixed this in revision 1304.

This expression will compile successfully, as the cast is returning a handle. The function argument will be the reference to that temporary handle.

Perhaps the compiler really should warn that the reference is to a temporary handle and thus any changes to it won't be reflected in the calling function. But I'll work on that at a different moment.

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