Jump to content

  • Log In with Google      Sign In   
  • Create Account


Isaac Paul

Member Since 13 Jan 2013
Offline Last Active Aug 26 2014 06:23 AM

Topics I've Started

Need help tracking memory leak

04 March 2013 - 07:47 AM

I cannot for the life of me find this memory leak. I keep getting this:

 

 (0, 0) : ERR : GC cannot free an object of type 'RenderComponent', it is kept alive by the application

 (0, 0) : ERR : GC cannot free an object of type '_builtin_objecttype_', it is kept alive by the application

 (0, 0) : ERR : GC cannot free an object of type 'dictionary', it is kept alive by the application

 (0, 0) : ERR : GC cannot free an object of type 'Sprite', it is kept alive by the application


I implement all of these functions:
   void addRef();

    void release();

    int getRefCount();

    void setGCFlag();

    bool getGCFlag();

 

in the constructor i set the refCount to 1

 

and when I create a script object I notify the garbage collector like so:

SpriteScripted* ScriptObjectCreationCache::SSFactory() {
    SpriteScripted* obj = new SpriteScripted();
    
    if (spriteType == NULL)
        spriteType = engine->GetObjectTypeByName("Sprite");
    engine->NotifyGarbageCollectorOfNewObject(obj, spriteType);
    
    return obj;
}

 

 

this happens whenever I use that object type as a member property of a complete angelscript class (a class not declared in c++). However, i dont have a problem when I use a c++ defined class in a limited scope such as 'Texture' in setSpriteWithName:

(angelscript code; I dont have problems with Texture but I do have leaks with Sprite)

class RenderComponenet : Component
{
    Sprite sprite;

    void setSpriteWithName(string name) {
        Texture texture(name);
        sprite.setTexture(@texture);
    }
}

 

If anyone can see that I'm missing anything please let me know.

 

Thank you.


Register object behavior with pointer to instance function

28 February 2013 - 10:49 AM

Is it possible to pass a pointer to an instanced class method (&creationsClass.createScriptObject) when registering an object behavior?

 

I need specific behavior for certain script objects when they're created. I'm trying to avoid using static variables and classes as much as possible which doesn't allow me to simply create a static variable to store the object type for the garbage collector and many other things I need to instantiate a script object.

 

I kind of want to do something like this (but obviously it doesn't work):
 

#define asInstanceMethod(c,m) asSMethodPtr<sizeof(c)>::Convert((&c.m))

void Texture::registerAS(asIScriptEngine* engine, ScriptObjectCreationCache& creationCache) {
    int r;
    static const char* const strComponent = "Texture";
    r = engine->RegisterObjectType(strComponent, sizeof(Texture), asOBJ_REF | asOBJ_GC); assert(r >= 0);
    r = engine->RegisterObjectBehaviour(strComponent, asBEHAVE_FACTORY, "Texture@ f()", asInstanceMethod(creationCache, TSFactory), asCALL_CDECL); assert( r >= 0 );
    r = engine->RegisterObjectBehaviour(strComponent, asBEHAVE_FACTORY, "Texture@ f(const string &in)", asInstanceMethod(creationCache, TSFactoryArg), asCALL_CDECL); assert( r >= 0 );
    
    registerMembers<Texture>(engine, strComponent);
}

 

 

I would greatly appreciate any additional info. 

 

 

edit: I left a pretty crappy post earlier because I had to quickly go somewhere.. I fixed it up now ;)


what does offset point to in GetProperty

23 February 2013 - 12:35 PM

so for get property in the asScriptObject class:

 

GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, int *offset = 0, bool *isReference = 0, asDWORD *accessMask = 0);

 

It assigns an offset which I assume is pointing to the data for that property, but i can't exactly tell what it is pointing to. Is it the actual raw data or some sort of angelscript wrapper?

 

What I'm trying to accomplish is assigning to a angelscript class's members. I need to be able to assign values (ints, ect) and references to other script objects.

 

Any help would be greatly appreciated smile.png


Trying to register a function that returns a asIScriptObject

23 January 2013 - 07:32 AM

I have a function like this:

 

asIScriptObject* ComponentScripted::getProperty(const std::string &key) const 

 

and I'm registering it like this:

 

r = engine->RegisterObjectMethod(strComponent, "?& get(const string &in) const", asMETHODPR(ComponentScripted,getProperty,(const std::string&) const,asIScriptObject*), asCALL_THISCALL); assert( r >= 0 );

 


However, it doesn't seem like ?& is a valid return type. How would I return a asIScriptObject back to the script from c++?

 

Any help would be greatly appreciated. Thank you.


PARTNERS