Assert happens on TreeView


#1

Hi Jules,

I am using TreeView and custom component for TreeView item.

I get an assert when the TreeView is painted. Following is call history when click the open/close box if item.

Could you suggest me to avoid this assertion?

void TreeViewContentComponent::paint (Graphics& g) { if (owner->rootItem != 0) { owner->handleAsyncUpdate(); <--- jump

[code]void TreeView::handleAsyncUpdate()
{
if (needsRecalculating)
{
needsRecalculating = false;

    const ScopedLock sl (nodeAlterationLock);

    if (rootItem != 0)
        rootItem->updatePositions (0);

    ((TreeViewport*) viewport)->updateComponents();

    if (rootItem != 0)
    {
        viewport->getViewedComponent()
            ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
                       rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));   <--- jump[/code]

void Component::setSize (const int w, const int h) { setBounds (getX(), getY(), w, h); <--- jump

[code]void Component::setBounds (int x, int y, int w, int h)
{
// if component methods are being called from threads other than the message
// thread, you’ll need to use a MessageManagerLock object to make sure it’s thread-safe.
checkMessageManagerIsLocked

if (w < 0) w = 0;
if (h < 0) h = 0;

const bool wasResized  = (getWidth() != w || getHeight() != h);
const bool wasMoved    = (getX() != x || getY() != y);

#ifdef JUCE_DEBUG
// It’s a very bad idea to try to resize a component during its paint() method!
jassert (! (flags.isInsidePaintCall && wasResized)); <— Hit the assertion![/code]


#2

Doesn’t the comment in JUCE make that clear? You’ll calling a routine that in turn is resizing the component, which is specifically what the assert is telling you not to do.

Perhaps you could post a message from the paint call using postCommandMessage or some such and resize the component when the message is received.


#3

I read the comment but I just click the open/close box of the tree view and those components are created and used inside of TreeView, which I can’t touch.

The custom component I use is a component which has a Label as its child. I don’t call any sizing function in their constructor. It is created in the createItemComponent() method of my custom TreeViewItem.

Component* CMyLibraryTreeViewItem::createItemComponent() { CMyLibraryTreeViewItemComponent* pComponent = new CMyLibraryTreeViewItemComponent(this); return pComponent; }


#4

Ahh… sorry, I found a similar post…

http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=2430


#5

I guess I spoke too soon! Sorry about that.

I’m glad you found an answer.


#6

I’ve checked out the latest JUCE from svn and the problem seems to be fixed. Thanks!

Masa


#7