Hello, I'm thinking about all problems I'll have to face when implemening hot-reloading of scripts.
Currently, I assume that I'll use the Serializer add-on.
I have difficulty to find a good solution against the following problem:
// In C++ (simplified)
class ScriptObject
{
int addRef();
int release();
// etc...
};
class Foo : public ScriptObject
{
string name;
};
class Bar : public ScriptObject
{
Foo * foo; // A function is used to bind this field to AS
};
// In AS
//-----------
// Script before hot reload:
Foo@ foo; // Globals
Foo@ foo2; // Global too etc
Bar@ bar;
Bar@ bar2;
// Somewhere:
foo.name = "Yay";
bar.foo = foo;
bar2.foo = foo;
//-----------
// Script after hot reload:
// The user removed foo and foo2
Bar@ bar;
Bar@ bar2;
// Somewhere else:
print(bar.foo);
print(bar2.foo);
// Expected: printing "Yay" twice, coming from the same Foo instance.
First, how can we serialize Bar?
- Save foo as a full instance?
Despite "Yay" will be printed twice,
we'll end up with two Foo instances instead of a shared one...
- Just save the address of foo in it, not its value?
Foo is deleted in the process of recompiling, so the print will badly crash in C++.
- Call addRef on each C++ objects before recompiling, so they stay in memory when recompiling?
Then, how would we prevent objects from leaking?
I'm new to hot-reloading with AngelScript, so does someone has an idea how to handle this case?