Is it possible to set a free function to user data

edited December 2013 in Help request
This is giving me quite some trouble and extra code write.

Just wondering, can I set a function that will be called upon my object deletion ti free my object user data?

Not sure if the question is clear, but I wanted to use this:
  orxObject_SetUserData(newMonster, newMonsterInfo);

orxObject_SetLifeTime(monster, 2.0);

But my user data needs to be freed (actually given back to a memory bank).

Thanks in advance.


  • edited December 2013
    Hi Knolan,

    I'm assuming you're not using Scroll as the UserData attachment would be used by Scroll and not available for your own needs.
    You also wouldn't have this problem as your own ScrollObject derivates would have their OnDelete() method being called before destruction.

    With orx, the way to do this is by listening to the orxEVENT_TYPE_OBJECT events. Then, in your event handler, the ID you're interested in is orxOBJECT_EVENT_DELETE.
    orxSTATUS orxFASTCALL MyObjectHandler(const orxEVENT *_pstEvent)
      if((_pstEvent->eType == orxEVENT_TYPE_OBJECT) && (_pstEvent->eID == orxOBJECT_EVENT_DELETE))
        // Gets user data (and do whatever must be done with it)
        // ...
      return orxSTATUS_SUCCESS;
  • edited December 2013
    Thanks iarwain, solved my problem.

    Would it be possible to add this feature (a free function for the user data in the orxOBJECT struct) in the object in the future? It seems to me that this would be a much simpler and better way to handle it.
  • jimjim
    edited December 2013
    This is already available in Scroll as Iarwain mentioned, you can look into Scroll to know how it is done, then you might implement an easier or simpler version if you like.
Sign In or Register to comment.