Hello again.
I am using angelscript in the Generic form, and am running into an issue with new and delete, along with memory...
Now in the graphic's engine I am using, Ogre3D, they override the new and delete operator. I am asuming this is causing an issue with angelscript. I tried to disable the memory manager (new / delete overrides), however i think it is still sneaking in...
First off here is my registration methods...
// Ogre::Vector3
// Register object type, constructor, destructor and assignment
r = as->RegisterObjectType("Vector3", sizeof(Vector3), asOBJ_CLASS_CDA); assert(r >= 0);
r = as->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(OgreScriptBindings::Vector3Constructor), asCALL_GENERIC); assert( r >= 0 );
r = as->RegisterObjectBehaviour("Vector3", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(OgreScriptBindings::Vector3Destructor), asCALL_GENERIC); assert( r >= 0 );
r = as->RegisterObjectBehaviour("Vector3", asBEHAVE_ASSIGNMENT, "Vector3 &f(const Vector3 ∈)", asFUNCTION(OgreScriptBindings::Vector3Assignment), asCALL_GENERIC); assert( r >= 0 );
So when i am calling my Construct method this returns a Vector3 but the data types are empty...
void OgreScriptBindings::Vector3Constructor(asIScriptGeneric *gen)
{
// Construct the vector3 in memory
Vector3 *thisPtr = (Vector3 *)gen->GetObject();
new(thisPtr) Vector3();
// TODO: Why do i have to do this...?
thisPtr->x = 0; thisPtr->y = 0; thisPtr->z = 0;
}
This seams to work in that the x,y,z member variables are are manually initialized. However the constructor should be doing this, right? A call like this...
void OgreScriptBindings::Vector3Constructor(asIScriptGeneric *gen)
{
// Construct the vector3 in memory
Vector3 *thisPtr = (Vector3 *)gen->GetObject();
//new(thisPtr) Vector3();
thisPtr = new Vector3();
// TODO: Why do i have to do this...?
//thisPtr->x = 0; thisPtr->y = 0; thisPtr->z = 0;
}
Will initialize the member variables. However once i leave that function and come back to the destructor, the first code segment above retains the values, and the last method does not.
And more so, when i go to call a delete the Ogre memory manager kicks back in and causes an error in the overriden delete.
I saw a line in the manual that says...
Quote:
It is also possible to override how the memory is allocated for an object type, but this will not be described in this article. This can be useful if the object type is allocated from for example a memory pool, or if it is allocated from a DLL which uses another memory heap than the main application.
Is this the solution, to my problems, as i can not seam to find away to diable the memory manager completely in Ogre... I am also going on over to the ogre forums to check and see if anyone else has had issues with scripting engines and the Ogre Memory manager.
Thanks Again.