On 15/03/2013 at 09:54, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform:
Language(s) : C++ ;
---------
I'm having a hard time figuring out how to create and store multiple bitmaps into an array. Without getting memory leaks.
All I want to do is push a button on my GeDialog plugin, and have a new image be created and stored in an array.
I've tried all kinds of experiments to try and get the idea what exactly is going on. But I still can't achieve the simple task of adding multiple bitmaps to an array.
This is what I've learned so far:
-If I Alloc a bitmap and a GeDynamicArray as class members. I can create an image using that Alloc and Push the bitmap image into the array. And then I can free them both in the class's destructor.
That gives me one image in the array. With no memory leaks.
But...Every time I execute this. Every single image that was previously stored in the array will be replaced by the last one created. So I have an array filled with copies of the same image.
-If I Alloc a bitmap somewhere other than the class. I can't free it in the class's destructor anymore.
I must free it in the same local scope where I created it. And that's proving to be difficult to manage.
-If I use Alloc locally in my button code to create a new image every time the button is pressed. I do get what I want. I do get multiple images saved to the array. And they are all unique images (not the same image) just like I want.
But I also get memory leaks. Because all of the allocations have not been freed.
Does anyone a have a simple example of saving images to an array?
I can't figure out what C++ needs to do this. Without memory leaks.
In Coffee and Python all of this memory stuff is handled for me. But C++ is different.
-ScottA