Avoid jassert crash trying to draw into a zero Rectangle

Greetings,

An assertion failure I hit (in JUCE v5.4.5) could be avoided using the patch below. I don’t know exactly what was going on, but I was drawing a very small Document Window (maybe 10x10), and I think maybe the system was trying to add the JUCE logo in it - guessing from code I read on the stack.

pwd
…/JUCE/modules/juce_gui_basics/drawables
diff -cb juce_Drawable_before.cpp juce_Drawable_after.cpp
*** juce_Drawable_before.cpp 2019-11-23 17:33:03.000000000 +0800
— juce_Drawable_after.cpp 2019-11-23 17:33:21.000000000 +0800


*** 101,107 ****
— 101,109 ----
void Drawable::drawWithin (Graphics& g, Rectangle destArea,
RectanglePlacement placement, float opacity) const
{

  • if (destArea.getWidth()>0 && destArea.getHeight()>0 ) {
    draw (g, opacity, placement.getTransformToFit (getDrawableBounds(), destArea));
  • }
    }

Independent of the actual problem (I don’t know, if I wanted to check at that point or rather earlier), there is the option of if (!destArea.isEmpty())