void opCast(?&out) on null handle?

Started by
3 comments, last by Miss 7 years, 5 months ago

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!

Advertisement

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).

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'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?

I've fixed this in revision 2360.

I'm not sure when I'll release 2.31.2, but it could be any day now.

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

Awesome, thank you! smile.png

This topic is closed to new replies.

Advertisement