I have an object, that I want to add some data members to using script, like this.
shared class TestObject : IObject
{
TestObject(Object @object)
{
me = object;
object.AddData("TestData1");
object.AddData("TestData2");
}
Object @me;
}
The test data members look like this, just for testing at the moment.
shared class TestData1 : IData
{
TestData1(Data @data){
me = object;
}
Data @me;
};
shared class TestData2 : IData
{
TestData2(Data @data){
me = object;
}
Data @me;
};
This all works fine, until I shut down and the TestObject releases the data members. The first data member always releases ok, but the second one will crash with an access violation. If I comment out the second data member (so I'm only adding one), then it works ok. As soon as I try to add more than one, it starts crashing after the first one when calling Release.
Here is the c++ code for adding a data member to an object.
asIScriptObject* Object::AddData(std::string type)
{
asIScriptObject* data = CreateNewData(type);
data->AddRef();
return data;
}
The exception looks like this, and always happens in
asCScriptEngine::CallObjectMethod when calling asCScriptObject::Destruct.
Unhandled exception at 0x00EF5204 in Project.exe: 0xC0000005: Access violation reading location 0xBAADF019.
I've been stumped with this for a long time. Any ideas?