Popup menu in jucedemo raises an assert


#1

Hi,

In the widgets juce demo, if I click on the “click for a popup menu” button, I get an assert failure. This happens with v1.44 and with the latest svn version. It works fine on Mac OS X, so it might be platform specific. Attached is gdb output for v1.44, it seems that an ellipse got crazy coordinates.

Is this just a demo bug or does it hide some deeper problem ?
Thanks,

GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) r
Starting program: /home/nes/tmp/juce/extras/juce demo/build/linux/build/jucedemo
[Thread debugging using libthread_db enabled]
[New Thread -1214391920 (LWP 32645)]
JUCE v1.44
Time and date: 3 Aug 2007 11:50:54 am
Operating system: Linux
CPU vendor: GenuineIntel
CPU speed: 2793MHz

Number of CPUs: 2
CPU has MMX: yes
CPU has SSE: yes
CPU has SSE2: yes
CPU has 3DNOW: no
Memory size: 1003MB
Current executable file: /home/nes/tmp/juce/extras/juce demo/build/linux/build/jucedemo
Current application file: /home/nes/tmp/juce/extras/juce demo/build/linux/build/jucedemo
User home directory: /home/nes
User documents directory: /home/nes
User application data directory: /home/nes
Common application data directory: /var
Temp directory: /var/tmp


[New Thread -1214534768 (LWP 32648)]
JUCE Assertion failure in ../../src/juce_appframework/gui/graphics/contexts/juce_Graphics.cpp, line 495

Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread -1214391920 (LWP 32645)]
juce::Graphics::fillEllipse (this=0xbf94b3dc, x=138281760, y=1.11104627e+09, width=30, height=40)
    at ../../src/juce_appframework/gui/graphics/contexts/juce_Graphics.cpp:497
497         Path p;
(gdb) bt
#0  juce::Graphics::fillEllipse (this=0xbf94b3dc, x=138281760, y=1.11104627e+09, width=30, height=40)
    at ../../src/juce_appframework/gui/graphics/contexts/juce_Graphics.cpp:497
#1  0x08060fbd in CustomMenuComponent::paint (this=0x8628650, g=@0xbf94b3dc) at ../../src/demos/WidgetsDemo.cpp:201
#2  0x08136ed3 in juce::Component::paintEntireComponent (this=0x8628650, originalContext=@0xbf94b3dc)
    at ../../src/juce_appframework/gui/components/juce_Component.cpp:1721
#3  0x0813709a in juce::Component::paintEntireComponent (this=0x862a548, originalContext=@0xbf94b3dc)
    at ../../src/juce_appframework/gui/components/juce_Component.cpp:1753
#4  0x0813709a in juce::Component::paintEntireComponent (this=0x862a050, originalContext=@0xbf94b3dc)
    at ../../src/juce_appframework/gui/components/juce_Component.cpp:1753
#5  0x081aae18 in juce::ComponentPeer::handlePaint (this=0x862b3e8, contextToPaintTo=@0xbf94b464)
    at ../../src/juce_appframework/gui/components/windows/juce_ComponentPeer.cpp:391
#6  0x081bfda2 in juce::LinuxComponentPeer::LinuxRepaintManager::performAnyPendingRepaintsNow (this=0x862b4a8)
    at platform_specific_code/juce_linux_Windowing.cpp:1749
#7  0x081c0e53 in juce::LinuxComponentPeer::LinuxRepaintManager::timerCallback (this=0x862b4a8)
    at platform_specific_code/juce_linux_Windowing.cpp:1700
#8  0x080d92b2 in juce::InternalTimerThread::handleMessage (this=0x83b9680) at ../../src/juce_appframework/events/juce_Timer.cpp:260
#9  0x080d7671 in juce::MessageManager::deliverMessage (this=0x83b4bd0, message=0xb6e004e8)
    at ../../src/juce_appframework/events/juce_MessageManager.cpp:111
#10 0x081b6459 in juce::juce_dispatchNextMessageOnSystemQueue (returnIfNoPendingMessages=false)
    at platform_specific_code/juce_linux_Messaging.cpp:362
#11 0x080d74a1 in juce::MessageManager::dispatchNextMessage (this=0x83b4bd0, returnImmediatelyIfNoMessages=false,
    wasAMessageDispatched=0x0) at ../../src/juce_appframework/events/juce_MessageManager.cpp:150
#12 0x0813993e in juce::Component::runModalLoop (this=0x862a050) at ../../src/juce_appframework/gui/components/juce_Component.cpp:1420
#13 0x0819173e in juce::PopupMenu::showMenu (this=0xbf94bba8, x=593, y=623, w=200, h=24, itemIdThatMustBeVisible=0, minimumWidth=0,
    maximumNumColumns=0, standardItemHeight=0, alignToRectangle=true, componentAttachedTo=0x861f2d0)
    at ../../src/juce_appframework/gui/components/menus/juce_PopupMenu.cpp:1642
#14 0x081919cd in juce::PopupMenu::showAt (this=0xbf94bba8, componentToAttachTo=0x861f2d0, itemIdThatMustBeVisible=0, minimumWidth=0,
    maximumNumColumns=0, standardItemHeight=0) at ../../src/juce_appframework/gui/components/menus/juce_PopupMenu.cpp:1714
#15 0x080623e9 in WidgetsDemo::buttonClicked (this=0x83e2e38, button=0x861f2d0) at ../../src/demos/WidgetsDemo.cpp:1233
#16 0x081416e5 in juce::Button::sendClickMessage (this=0x861f2d0, modifiers=@0xbf94c03c)
---Type <return> to continue, or q <return> to quit---
    at ../../src/juce_appframework/gui/components/buttons/juce_Button.cpp:374
#17 0x081423e3 in juce::Button::internalClickCallback (this=0x861f2d0, modifiers=@0xbf94c03c)
    at ../../src/juce_appframework/gui/components/buttons/juce_Button.cpp:305
#18 0x0814211f in juce::Button::mouseDown (this=0x861f2d0, e=@0xbf94c034)
    at ../../src/juce_appframework/gui/components/buttons/juce_Button.cpp:439
#19 0x0813aec4 in juce::Component::internalMouseDown (this=0x861f2d0, x=109, y=13)
    at ../../src/juce_appframework/gui/components/juce_Component.cpp:2542
#20 0x081abfda in juce::ComponentPeer::handleMouseDown (this=0x83c7750, x=109, y=13, time=1186134662054)
    at ../../src/juce_appframework/gui/components/windows/juce_ComponentPeer.cpp:244
#21 0x081be432 in juce::LinuxComponentPeer::handleWindowMessage (this=0x83c7750, event=0xbf94c3c4)
    at platform_specific_code/juce_linux_Windowing.cpp:1279
#22 0x081bb774 in juce::juce_windowMessageReceive (event=0xbf94c3c4) at platform_specific_code/juce_linux_Windowing.cpp:2453
#23 0x081b64ff in juce::juce_dispatchNextMessageOnSystemQueue (returnIfNoPendingMessages=false)
    at platform_specific_code/juce_linux_Messaging.cpp:391
#24 0x080d74a1 in juce::MessageManager::dispatchNextMessage (this=0x83b4bd0, returnImmediatelyIfNoMessages=false,
    wasAMessageDispatched=0x0) at ../../src/juce_appframework/events/juce_MessageManager.cpp:150
#25 0x080d7609 in juce::MessageManager::runDispatchLoop (this=0x83b4bd0)
    at ../../src/juce_appframework/events/juce_MessageManager.cpp:194
#26 0x08085c81 in juce::JUCEApplication::main (commandLine=@0xbf94c538, app=0x83b4a58)
    at ../../src/juce_appframework/application/juce_Application.cpp:206
#27 0x08085eb3 in juce::JUCEApplication::main (argc=1, argv=0xbf94c614, newApp=0x83b4a58)
    at ../../src/juce_appframework/application/juce_Application.cpp:289
#28 0x0804d2f1 in main (argc=1, argv=0xbf94c614) at ../../src/ApplicationStartup.cpp:176

#2

doh - how embarrassing! It’s just an uninitialised variable in the demo code. Must have been there for years, strange that I never spotted it…

Stick this line into WidgetsDemo.cpp and it’ll be fine:

[code] CustomMenuComponent()
{
// set off a timer to move a blob around on this component every
// 300 milliseconds - see the timerCallback() method.
startTimer (300);

    // initialise the position before we start..
    timerCallback();
}

[/code]

Thanks!


#3

Thanks for you fast reply!
I think the fix is actually just a bit more complex, because in timerCallback():

void timerCallback()
    {
        blobX = Random::getSystemRandom().nextInt (getWidth());
        blobY = Random::getSystemRandom().nextInt (getHeight());
        repaint();
    }

the random generator needs the width and the height of the menu, which is iniatilized to 0 in the constructor. This results in a assert failed “maxValue>0” in the random generator. After changing this, it seems to work here :slight_smile:


#4

doh again! I should probably have tried that before I posted it!


#5