DragAndDrop newly created component

Hi,
I have the following Drag&Drop related question.

I have sort of a GUI designer with 2 windows. One contains the list of elements the second one is the layout window in which you arrange the GUI. I have a drag&drop action implemented between the 2 document windows (don’t think that’s the problem at this point). The startDragging method requires me to supply a component pointer. The thing is that what I drag is not a component at the moment, it is just an xml defined rectangular area. I create the component at the moment the drag action starts and pass it to the startDragging. In the DragAndDropTarget::itemDropped, i just take the sourceComponent and put it in the OwnedArray. It works but I always get LeakedObjectDetector assert while closing the application. So it seems there is a problem but I don’t see where. I known that even if I used this technique in the end, I would have to solve the case when the item is not dropped at the target, i.e. I would have to free the component anyway. I was thinking of using shared pointers but first I need to know whether I can even do it the way I described.

BTW if i place some kind of dummy component in the source window and put it in the startDragging instead, and in sourceDescription pass an information what exactly should be created and then create the component in the itemDropped handler there are no leak asserts (but the problem is that I see the dummy component as a drag icon which I don’t want to - of course). It must have something to do with WeakReference or making a copy somewhere or something.

Also is there in JUCE an equivalent to C++11/14 shared_ptr? There is a ReferenceCountedObject but that is not exactly the same, as it requires the class to be a child of ReferenceCountedObject.

Thanks!

SharedResourcePointer

I don’t think SharedResourcePointer is what he’s looking for. That’s more of a singleton-like object.

@Aros Is there any reason you can’t just use a std::shared_ptr if that’s the behaviour you’re after?

I can, but I don’t think that is going to solve the problem. Or maybe I could pass the component as shared_ptr and then make a copy of it in itemDropped. But the need of making a copy is something I usually try to avoid. Anyway, I will try it and let you. Even if it does not solve the problem it will at least help us pinpoint what’s causing it.

It will however take some time as I have just left for vacation :slight_smile: