Hi Jules,
I’ve enabled stopping in all exception while debugging.
Sometime, when I start a juce code, I get an exception which is not handled correctly (only in enterMainApplicationLoop => exit). I think this is an error in general Juce code. This occurs when ImageButton is used Here is what’s happening, and how to avoid it:
[list]
- WinMain is called (or whatever entry point)
- enterMainApplicationLoop is called
- runDispatchLoop is called, and then dispatchMessage
- juce_wndProc is then called with a WM_MOVE message (no WM_PAINT message has been processed yet)
- doMouseMove is called
- handleMouseEnter is then called because the current captured HWND is not ours (which doesn’t exists yet)
- Then the code tries to find what component is at the cursor position
- The hitTest method of ImageButton is called, but because ImageButton:: paintButtion is called yet, the imageW and imageH members are still not defined (they are 0). hitTest then tries to divide by imageW and imageH which causes a divide by zero exception.
[/list]
To avoid this, I think the correct behaviour would have been to change in the setImages method (line 108 of juce_ImageButton.cpp):
if (resizeButtonNowToFitThisImage && normalImage != 0)
{
setSize (normalImage->getWidth(),
normalImage->getHeight());
}
by
if (resizeButtonNowToFitThisImage && normalImage != 0)
{
setSize (normalImage->getWidth(),
normalImage->getHeight());
imageW = normalImage->getWidth(); imageH = normalImage->getHeight();
}
Maybe imageX and imageY should be changed too.
Please confirm, and/or take notice for next update.
Cheers,
Cyril
