Sign in to follow this  

Bug with @&

This topic is 2042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

C++

[CODE]
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);


[/CODE]


This script code work!
[CODE]
Node @n = cam.FirstNode();

xml.GetNode( n );[/CODE]


But, This code crash program!


[CODE]

xml.GetNode( cam.FirstNode() );
[/CODE]

Reference no valid!

Share this post


Link to post
Share on other sites
[quote name='Andreas Jonsson' timestamp='1336671496' post='4939059']
Is it GetNode() or SetNode()?
[/quote]

Sorry, need go sleep![img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img] yes i use [b]asEP_ALLOW_UNSAFE_REFERENCES [/b]

Create example:

[CODE]
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 );[/CODE]

Script:

[CODE]

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() );

}
[/CODE]

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

as_context.cpp[ 2522 ]

[CODE]
case asBC_RDR4:
*(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD**)&regs.valueRegister;
l_bc++;
break;[/CODE] Edited by FDsagizi

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[CODE]PrintLink_4( GetTestLink() );[/CODE]

this code no compilate - greate![img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

but this compilate and crash!

[CODE]PrintLink_4( cast<TestLink@>( GetTestLink() ) );[/CODE] Edited by FDsagizi

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this