Jump to content
  • Advertisement
Sign in to follow this  
FDsagizi

Bug with @&

This topic is 2256 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 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!

Share this post


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

Share this post


Link to post
Share on other sites

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

this code no compilate - greate!smile.png

but this compilate and crash!

PrintLink_4( cast<TestLink@>( GetTestLink() ) ); 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!