Advertisement

Serializing an object handle holding the only reference to an object

Started by August 10, 2022 12:59 PM
9 comments, last by Varrok 1 year, 10 months ago

Hello again ?

I'm having some troubles with serialization of a class member / handle.

Consider the following scenario (AS class initialized directly from C++):

class Main
{
    private CppObj@ m_cppObj;
    Main(SomeOtherCppObj& someOtherCppObj)
    {
        @m_cppObj = CppObj(someOtherCppObj);
    }

which is meant to mimic C++ behavior of:

    class Main
    {
    public:
        explicit Main(OtherObject* pOtherObj) : m_obj(pOtherObj)
        {
        }
        Object m_obj;
    };

Handles are used in the AS example because, sadly, the member initializer lists currently don't seem to be a thing in AngelScript. Please note that CppObj/Obj only has an explicit constructor with one parameter, and so it will simply not run if it was declared as a non-handle AS object due to No default constructor for object of type 'CppObj'.

The issue I have that when trying to reload the script the object that handle m_cppObj points to never seems to be restored, using unaltered AS serializer add-on. On one hand, I can kind of understand why it wouldn't - after all, the object itself is declared locally….

How to tackle this issue?

Did you tell the CSerializer object how to serialize the SomeOtherCppObj type with a call to AddUserType?

http://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_serializer.html

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

Advertisement

Yes, as a general rule I add all custom cpp classes to serializer via AddUserType

OK. I'll investigate this and try to reproduce the problem in order to identify the cause.

Though I'm very short on time right now so it may take a while.

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

Trying to reproduce the problem is painful so, like the last time, I prepared a sample project with the issue shown:

https://www.sendspace.com/file/n39c9n

Though when I first attempted it, to save time I tried to use CScriptArray instead of making a custom CppObj struct. The serializer didn't like it (Array Handle storing/restoring) at all and crashed C++. Doesn't bother me personally (at least not yet), but it's probably worth reporting as well:

https://www.sendspace.com/file/mld1tr

Thanks, that helps.

I'll investigate both problems as soon as I can. It is likely that the CSerializer simply never had implementation to support class members as handles (though it is curious as to why nobody reported it until 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

Advertisement

Bump, I guess - projects reuploaded

https://www.dropbox.com/s/o11ydqkw9rlv7e8/angel_issue_mvp_issue2.zip?dl=0
https://www.dropbox.com/s/yhifvtqxpo4obag/angel_issue_mvp_issue3.zip?dl=0

Thanks for the reminder. I hadn't forgotten, but other issues came up that I had to work on first.

I'll try to work on this one next.

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've finally fixed this in revision 2821.

https://sourceforge.net/p/angelscript/code/2821/

Make sure to review the code for the tests that I included in test_addon_serializer.cpp. The comments with // FIX: shows where you need to change your code to work properly with the new version of the serializer add-on

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

Thank you very much! ❤️

Will check it when I get a chance to (soon)

This topic is closed to new replies.

Advertisement