Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Memory Leak Problem

    Scheduled Pinned Locked Moved SDK Help
    5 Posts 0 Posters 338 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 13/12/2011 at 08:59, xxxxxxxx wrote:

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

      ---------
      While checking my plugin code for memory leaks. I discovered that using Init(GeGetPluginPath()) in my CreateLayout() function is not letting go of some memory.
      Here is the message displayed by the c4d_debug.txt debugger:

      gui_newdialog.c<731>: 104 bytes at 19272928!  
      1 Blocks  
      *** Potential Memory Leak Detected ***
      

      The plugin is a GeDialog type plugin. But it uses external resource files instead of the built-in AddGizmo() style.

      Code Snippet:

      Bool myDialog::CreateLayout(void)  
      {  
        Bool result = TRUE;  
        GeResource dlg_res;  
        dlg_res.Init(GeGetPluginPath()); // <---This code creates a memory leak!!  
        result = LoadDialogResource(IDS_RESDIALOG, &dlg_res, 0);  //IDS_RESDIALOG is the items found in the .res file  
        
        
        //GUI stuff here  
        
        
        return TRUE;  
      }
      

      I'm new at memory management. And I've never seen init() cause a memory problem before.
      How do I free this so it doesn't show up in the debugger as a leak?

      -ScottA

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 13/12/2011 at 11:37, xxxxxxxx wrote:

        Hi,

        We need to allocate a custom resource only if we want to load resources from a custom resource path. We usually load resources from the res folder.
        If you look at Main.cpp of the SDK examples, you'll see a line:

        if (!resource.Init()) return FALSE; // don't start plugin without resource
        

        resource is a global GeResource allocated and freed by CINEMA 4D. It's declared at the end of the header file c4d_resource.h.

        So your code should just be like the one used in the SDK examples.
        And we don't need to pass GeGetPluginPath() to the Init() method because it's by default initialized with the plugin's main path. You can see the implementation of GeResource::Init(void) in c4d_resource.cpp.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 13/12/2011 at 13:32, xxxxxxxx wrote:

          Thanks Yannick.

          Good explanation about how the resource.Init() function works.
          Makes perfect sense.

          I fixed my loader code

              Bool res = GeDialog::CreateLayout();  
            res = LoadDialogResource(IDS_RESDIALOG,NULL,0);  
            return res; 
          

          Unfortunately doing that also killed my CustomBitmapButton in the process.

              GroupBegin(0,BFH_LEFT,2,0,"MySecondGroup",0);  
                    {  
                    BaseContainer bbc;                             //Create a container to hold our custom button gizmo              
                    bbc.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT);  //Make the button style raised so it looks like a button  
                    bbc.SetBool(BITMAPBUTTON_BUTTON, TRUE);      
                    myButton = (BitmapButtonCustomGui* )AddCustomGui(10001,CUSTOMGUI_BITMAPBUTTON,"MY BUTTON", 0L,80,80,bbc); //Adds the BitmapButton GUI to the dialog      
                    //myButton->SetImage(Osphere, FALSE); //Adds the sphere icon to the button if that's what you want  
                    myButton->SetImage(200000000, FALSE); //Adds our custom registered icon using it's ID#...Be sure to get a real ID# from c4dcafe.com. DON'T use this one in your public projects!  
                    }  
            GroupEnd();
          

          Without GeGetPluginPath() in my loader code. The button no longer shows up.
          Is there a way I can get this button to work again?
          I can post the entire .cpp code if you need it.

          -ScottA

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 13/12/2011 at 14:01, xxxxxxxx wrote:

            Do you call resource.Init() ?
            Your loader code should looks like this:

            if (!resource.Init()) return FALSE; // Call it at C4DPL_INIT_SYS plugin message
                                                                // As done in the SDK examples
              
            if (!GeDialog::CreateLayout()) return FALSE;
              
            return LoadDialogResource(IDS_RESDIALOG,NULL,0);
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 13/12/2011 at 15:17, xxxxxxxx wrote:

              I tried using that code but my button is still missing.

              *Edit- Never mind Yannick. I found the problem
              As usual. It was a really noobish mistake.
              I put "return res" under my dialog loading code. Instead of at the end of the CreateLayout(void) method in place of "return TRUE". 😊

              Like Kermit the frog says: "It's not easy being green:😉

              Thanks for the help,
              -ScottA

              1 Reply Last reply Reply Quote 0
              • First post
                Last post