Memory leak in MSG_DESCRIPTION_GETBITMAP [SOLVED]



  • On 15/09/2016 at 04:56, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi,

    I have an object with a BITMAPBUTTON defined in the description. I am setting the bitmap in MSG_DESCRIPTION_GETBITMAP. However, creating the object and letting the timeline play, my memory fills up continously.

    This is the code (there is no other code executed by the object except for GetDParameter/SetDParameter...see below).

      
    case MSG_DESCRIPTION_GETBITMAP:  
          {  
              DescriptionGetBitmap* dgb = static_cast<DescriptionGetBitmap*>(t_data);  
              switch(dgb->id[0].id)   
              {  
                  case ID_BMPBUTTON:  
                  {  
                      AutoAlloc<BaseBitmap> bmp;  
                      bmp->Init(500,100); bmp->Clear(255,255,255);  
                      dgb->bmp = bmp.Release(); //removing this line stops the memory filling up  
                  }  
                  break;  
              }  
          }  
          break;  
    
      
    Bool TestObject::GetDParameter(GeListNode* node, const DescID& id, GeData& t_data, DESCFLAGS_GET& flags)  
    {   
      switch(id[0].id)   
      {   
          case ID_BMPBUTTON:     
          {     
              BitmapButtonStruct bbs(static_cast<BaseMaterial*>(node), id, m_dirty);      
              t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON,bbs);    
              flags |= DESCFLAGS_GET_PARAM_GET;    
              break;  
          }  
      }      
      return Base::GetDParameter(node, id, t_data, flags);  
    }  
    Bool TestObject::SetDParameter(GeListNode* node, const DescID& id, const GeData& t_data, DESCFLAGS_SET& flags)  
    {   
      switch(id[0].id)   
      {   
      case ID_BMPBUTTON:  
          m_dirty=0;  
          flags |= DESCFLAGS_SET_PARAM_SET;     
          break;          
      }    
      return Base::SetDParameter(node, id, t_data, flags);  
    }  
    

    The docs state:

    Recipient should allocate a bitmap and assign this pointer. The sender must ensure that the bitmap is freed properly. (Normally this means that Cinema 4D does the freeing.)

    Am I doing something wrong? I thought that I am the recipient and C4D is the sender (otherwise it makes no sense that c4d does the freeing). Also dgb->bmp is always nullptr when it jumps into MSG_DESCRIPTION_GETBITMAP, so I actually have to fill it myself.

    Or should I have the bitmap in memory according to the object lifetime scope (i.e. allocate the bitmap as a class member...darn didn't try that yet, but it just got to my mind when writing this..checking right now. But how does c4d free it then?).

    Thanks



  • On 15/09/2016 at 05:04, xxxxxxxx wrote:

    Nope, having it as a member doesn't work and freezes instantly on the second frame (makes sense as c4d probably tries to free it internally as the docs state).

    Help please 😢



  • On 16/09/2016 at 02:13, xxxxxxxx wrote:

    Hello,

    with your given code and description I could not reproduce any memory issues so far with R18. What is the desired behaviour of the BitmapButton when you play the timeline? Should it update on every frame?

    You say that you test this on an object but inside your GetDParameter() function you cast the given node into a BaseMaterial.

    best wishes,
    Sebastian



  • On 16/09/2016 at 05:03, xxxxxxxx wrote:

    Hi Sebastian,

    thanks for your answer!
    Please ignore the BaseMaterial cast, this is just a typo. Of course it should be BaseObject (though this makes no difference. The pointer remains the same).

    Yes, it should update each frame as the bitmap content is time dependant.
    As the topic info states I am in R16 currently. But I just tried it in R18 (extented the RoundedTube object) and you are right, I don't get any memory leaks there!

    Did something change in that respect? Though I cannot remember any changes in that area. So I guess there is something wrong on my side, but as mentioned the object does nothing else. :-/

    Thanks. I double check

    P.S: You can move this thread into the normal sdk forum as it clearly is not reproducible.



  • On 19/09/2016 at 08:36, xxxxxxxx wrote:

    Hello,

    so far I could not find any difference in how R16 and R18 handle this message.

    Does your code update the bitmap for every frame? Looking at some internal code it seems to be a patter to increment the stored dirty value in GetDParameter() to achieve this behaviour.

    best wishes,
    Sebastian



  • On 19/09/2016 at 10:39, xxxxxxxx wrote:

    Hi Sebastian,

    thanks for your message! In the meantime I have found the culprit.

    For completeness: I thought no other code was evaluated but I had built into the wrong directory all the time and therefore it never updated the dynamic library file.
    Coz in that code I tried to trigger an update each frame by constructing a DescriptionGetBitmap struct myself and calling the message function of my object. This was the culprit of the memory leak!

    If there was a slap on forehead smiley, it would go here. Sometimes I wonder how I manage life... ^^

    Anyway, using the increment alone works as expected!

    Thanks again for pushing the discussion. You can mark this as solved.


Log in to reply