Hi.
I been working on game using AngelScript for a couple of months now and ran
into problems when I tried a new way of handling objects.
Now I will try to explain the system im using as good as possible.
If you know what is causing my problems or a better way to implent it,
I would really appreciate the help.
The objects look like this:
container --> smart pointer --> true pointer
The container holds a pointer to a smart pointer.
When there is no references to the smart pointer and it self delete.
The factory that creates the true object also deletes the true object.
If it is deleted the smart pointer's true pointer is set to NULL. And the factory releases it's reference to the smart pointer.
This means:
* You can destroy a objects true content even though there is still references to it. For example a mesh can be removed from the scene.
* That means the smart pointer doesn't handle the deletion of the true pointer, it only keeps track wether or not it's valid.
* The smart pointer self deletes when there is no containers that has references to it anymore and the factory ahs released its reference.
* You can create empty containers that holds no references. And assign containers to each other.
Example:
Entity myEntity;
void main()
{
myEntity.move(); // does nothing but generates a warning for empty container
// Creates a smart pointer and assign it to the container
myEntity = createEntity("myEntity", "entity.mesh");
Entity otherEntity;
// otherEntity is now equal to myEntity (they have the same smart pointer).
otherEntity = myEntity;
// The mesh entity.mesh is now destroyed and the factory has released it's
// reference. The smart pointer will remain as long as the containers exists
// or gets assigned a new one.
destroyEntity(otherEntity);
}
Now to start with I had alot of problems with bad pointers in assignment. But those are resorted now.
Problem now is that get a exception every time AngelScript tries to delete a
temporary object (used when copy from one object to another.).
The exception is caused at then end of the destructor.
Some of the code:
// assignment
ret = m_pEngine->RegisterObjectBehaviour("Entity", asBEHAVE_ASSIGNMENT,
"Entity& f(const Entity& in)", asFUNCTION(Script_OgreEntity::assign), asCALL_CDECL_OBJFIRST); ERR_AS(ret);
Script_OgreEntity& Script_OgreEntity::assign( Script_OgreEntity* self, Script_OgreEntity* other )
{
self->set( other->get() );
return *self;
}
// destructor
Script_OgreEntity::~Script_OgreEntity()
{
if (m_pObject)
m_pObject->release();
}
On a side note im using ogre 3d engine which has it's own memory manager.
Im not sure if thats causing the problem.
Got any ideas what I might be doing wrong?
I can paste more code if needed.