DragAndDropContainer bug


#1

Hi,
We’ve just found a bug in the DragAndDropContainer component.
When you dragging over a component and that component is deleted or replaced (same actually) you get an access violation.

the probem is in line 288

            if (currentlyOver != 0
                 && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
                currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);

i replaced it with this, now it seems to work fine.

            if (currentlyOver != 0) {
                Component* const over = dynamic_cast <Component*> (currentlyOver);
                if (over != 0 &&
					over->isValidComponent() &&
					! (sourceWatcher->hasBeenDeleted()) &&
					currentlyOver->isInterestedInDragSource (dragDescLocal, source)) 
				{
					currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
				}
			}

#2

hmmm.
I though i fixed it but i still have the same issue.
Of course the dynamic_cast fails on a pointer that isn’t valid anymore.

Component* const over = dynamic_cast <Component*> (currentlyOver); 

A deletionwatcher should also be set on the component you are dragging over. Any suggestions on how to fix this problem?


#3

Hmm. Yes, it’d need a deletionwatcher in there to catch that kind of thing. It involves quite a few changes, I’ll check something in to do it very soon…


#4

Thanx for the quick fix. Still a little error though.
Starting at line # 287

            else if (currentlyOverWatcher != 0 && !currentlyOverWatcher->hasBeenDeleted())
            {
                currentlyOver = 0;
                deleteAndZero (currentlyOverWatcher);
            }

should be

            else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
            {
                currentlyOver = 0;
                deleteAndZero (currentlyOverWatcher);
            }

#5

Thanks!