Sign in to follow this  

void opCast(?&out) on null handle?

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

I read this in the documentation:

"Remember that it is legal for the script to attempt a cast on a null pointer, in which case the result is also a null pointer. This means that the reference cast behaviour must not be implemented as a virtual class method, because then the call will crash if the object pointer is null."

However, if I actually implement this like this:

r = m_engine->RegisterObjectMethod(name, "void opCast(?&out)", asFUNCTION(ScriptClassCast), asCALL_CDECL_OBJFIRST); assert(r >= 0);

With this being the signature for ScriptClassCast:

static void ScriptClassCast(void* obj, void** outRef, int typeId);

I get a null pointer access exception on this line of Angelscript:

Derived@ test = cast<Derived>(foo.someNullHandle);

And the ScriptClassCast function to actually perform the cast is not called.

 

It looks like I'm mostly doing the same thing as the documentation states, except that I'm testing against the derived class at run-time (eg via "?&out")

 

Any help would be appreciated!

Share this post


Link to post
Share on other sites

I'll look into this.

 

That phrase from the manual is no longer accurate, and I'll have it corrected. The VM will first check if the handle is null and if so return null without calling the opCast method.

 

It looks like this check for null may be missing for opCast(?&out).

Share this post


Link to post
Share on other sites

I'll look into this.

 

That phrase from the manual is no longer accurate, and I'll have it corrected. The VM will first check if the handle is null and if so return null without calling the opCast method.

 

It looks like this check for null may be missing for opCast(?&out).

Ah, cool.

 

Looking forward to an update then. When is 2.31.2 planned to come out?

Share this post


Link to post
Share on other sites

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