Jump to content
  • Advertisement
Sign in to follow this  
Rain Dog

Possible bug

This topic is 4866 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

Man I wrote this topic once but must have pressed preview !! Anyways. I have something like the following: struct myStruct{ int x;}; class myClass{ public: vector<myStruct> myVec;} The class is registered just fine through AS as a property. Its other methods (not shown) work fine. I have registered std::vector using Deyja's tool. Everything generally works fine, however, when i do the following in script: //Script myStruct[] A; A = MyClass.myVec; The error message: Error: Can't implicitly convert from myStruct[]& to myStruct[]& Something is afoul.

Share this post


Link to post
Share on other sites
Advertisement
It does indeed look like a bug.

It is probably related to the changes I made in how array objects are handled by the compiler. I assume that you are using version 2.2.0 or 2.2.1 WIP 1, am I right?

I'll look into this as soon as I can.

Share this post


Link to post
Share on other sites
2.2.0WIP 5


I have not been aware of any release after that, but I looked at the site ( i generally come here ) and noticed that you have uploaded WIP2 even of 2.2.1

Share this post


Link to post
Share on other sites
Sorry about the late answer, but I've been very busy at work and only got some time to look into this now.

It seems that this isn't a bug after all, although AngelScript should definitely give some better error message in this case.

You must have registered the myVec property of MyClass before registering the overloaded MyStruct[] array type. This makes AngelScript think that myVec is a built-in array type, which is not compatible with the overloaded MyStruct[] array type.

The following test works:


// Configure engine
r = engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_CDECL); assert( r >= 0 );

r = engine->RegisterObjectType("MyStruct", sizeof(MyStruct), asOBJ_CLASS); assert( r >= 0 );

RegisterVector<MyStruct>("MyStruct[]", "MyStruct", engine);

r = engine->RegisterObjectType("MyClass", sizeof(MyClass), asOBJ_CLASS_CD); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("MyClass", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(MyClass_Construct), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("MyClass", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(MyClass_Destruct), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectProperty("MyClass", "MyStruct[] myVec", offsetof(MyClass,myVec)); assert( r >= 0 );

// Compile and execute script
engine->AddScriptSection(0, TESTNAME, script2, strlen(script2), 0);
r = engine->Build(0, &out);
if( r < 0 )
{
fail = true;
printf("%s: Failed to compile the script\n", TESTNAME);
}

r = engine->ExecuteString(0, "Test()", 0, &ctx);
if( r != asEXECUTION_FINISHED )
{
printf("%s: Failed to execute script\n", TESTNAME);

if( r == asEXECUTION_EXCEPTION )
PrintException(ctx);

fail = true;
}



The script is the following:


void Test()
{
MyStruct[] A;
MyClass B;
A = B.myVec;
Assert(A.size() == 2);
}



The constructor for MyClass, resizes the myVec array to 2 elements.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Ok, it's highly likely that that was the case. I have since changed the order in which my objects were registered so I can't say for sure if that was the problem or not.

I also changed property to use an accessor.


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!