🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Throwing script exception from factory function

Started by
4 comments, last by WitchLord 4 years, 7 months ago

If I throw a script exception from a factory function, aka a C++ constructor registered as a script factory function for a reference type, I get this assertion error:

Assertion failed: (m_regs.objectType != 0), function CleanReturnObject, file ../angelscript/source/as_context.cpp, line 4589.

More specifically, I'm writing a C++ class to wrap a network socket for script usage. In the Socket() constructor I have the usual BSD socket(), setsockopt() etc. procedure. I'm erroring out if each call fails and letting the script know via script exceptions which part of the process failed. The class is registered as a reference type in angelscript and has the normal addRef/release logic with `if (--ref == 0) delete this;`. `ref = 1;` is the first line of the constructor.

When one of the calls fails and the exception is thrown to the script, I get the above assertion failure message. This is how the exceptions are thrown to the script, followed by a `return;` from the constructor.


asGetActiveContext()->SetException("...", true);

Is this expected behavior?

Advertisement

Is your registered factory function returning a non-null value after setting the script exception? It should return null in this case.

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

Can you show me more on this? I haven't been able to reproduce the assert failure, even if the factory returns a non-null value.

Perhaps you can provide a short snippet of code that reproduces the problem?

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

Actually no. The factory function (static method) just returns new Socket(...) and the Socket constructor sets the script exception. I assumed it would be ref counted down and deleted after the exception handled by the script. I can modify the factory to check validity of the Socket and return nullptr instead. Thank you!

By the way, is this behavior/expectation documented? I've generally been a bit confused on how to handle returning from functions after setting a script exception without using C++ exceptions.

Sure I can try to reduce it to a test case for you. Might take some time as my project is quite large.

It is briefly mentioned in the description for the registered factory function and for the SetException method.

However, the documentation probably needs to be clarified on this part. I'll take note on it.

 

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

This topic is closed to new replies.

Advertisement