Puzzle: mouseDrag and ListBox row components


#1

Quick explanation: Trying to allow dragging of ListBox row components to scroll the list. If mouseDrag is used in the component at the top of the list, if you scroll up, when the component leaves the top (and i assume gets deleted or reassigned) i get a heap corruption.

Any ideas on a solution, or is this just not possible?


#2

The stack trace at the crash looks like this:


!juce::ArrayAllocationBase<juce::Graphics::GraphicsState *>::setAllocatedSize(const int numElements=8)  Line 94 + 0x15 bytes	C++
!juce::ArrayAllocationBase<juce::Graphics::GraphicsState *>::ensureAllocatedSize(int minNumElements=1)  Line 134	C++
!juce::OwnedArray<juce::Graphics::GraphicsState,juce::DummyCriticalSection>::add(const juce::Graphics::GraphicsState * const newObject=0x00e92410)  Line 266	C++
!juce::Graphics::saveStateIfPending()  Line 180	C++
!juce::Graphics::setColour(const juce::Colour & newColour={...})  Line 199	C++
!juce::LookAndFeel::drawResizableWindowBorder(juce::Graphics & g={...}, int w=300, int h=200, const juce::BorderSize & border={...}, juce::ResizableWindow & __formal={...})  Line 1482 + 0x25 bytes	C++
!juce::ResizableWindow::paint(juce::Graphics & g={...})  Line 305 + 0x80 bytes	C++
!juce::DocumentWindow::paint(juce::Graphics & g={...})  Line 181	C++
!juce::Component::paintEntireComponent(juce::Graphics & originalContext={...})  Line 1735 + 0x13 bytes	C++
!juce::ComponentPeer::handlePaint(juce::LowLevelGraphicsContext & contextToPaintTo={...})  Line 393	C++
!juce::Win32ComponentPeer::handlePaintMessage()  Line 1386	C++

… though there’s a bunch of malloc stuff above it and stuff that has no source to list.

I can’t really figure out what the problem is; i’ve tried dragging from a more central row, and used a keyboard shortcut to delete the listbox, and i didn’t get any complaints about dragging a component that has been destroyed.

There are some calculations involved (as I have to convert pixels/proportion), but the basic move is:

Row::mouseDrag - ownerList->scroll (amount)
ListView::scroll - listbox->setVerticalPosition (newPosition)

Is doing it in this way a problem [ultimately calling setVerticalPosition from mouseDrag]


#3

No problem any more - I’ve solved it by using a MouseListener on the listbox itself, to respond to the messages in my parent class.