# Bug in DropShadow::drawForRectangle

**URL:** <https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911>\
**Category:** General JUCE discussion\
**Created:** [August 26, 2017, 7:25pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911 "2017-08-26T19:25:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [August 26, 2017, 7:25pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/1 "2017-08-26T19:25:45Z")

</div>

When using a DropShadow object with the DropShadow::drawForRectangle function, there are visible gaps between the corner segments.

![dropshadow_gap](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/f/f60c8487f03bb4f7a24ab3b8c3bc03b5903997de.png)

It seems this line here:

```
const float radiusInset = (radius + 1) / 2.0f;

```

right at the start of the drawForRectangle function is to blame.

If I change it to

```
const float radiusInset = radius / 2.0f;

```

the gaps go away. No overlap or anything was noticed, it looks simply perfect.

Should I open an issue on GitHub or does this suffice?

Regards,  
Mike

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [August 26, 2017, 7:47pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/2 "2017-08-26T19:47:57Z")

</div>

It seems this is platform specific. On Windows you get the gap, on macOS you don’t. Maybe some weird compiler / rounding issue?

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [August 26, 2017, 7:50pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/3 "2017-08-26T19:50:53Z")

</div>

Is this on a Retina (or hi res.) display?

I haven’t noticed that in our plug-in on either platform.

Rail

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [August 26, 2017, 7:52pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/4 "2017-08-26T19:52:30Z")

</div>

On macOS with a retina display, it works fine. On Windows with a non-retina display you get the gap.

MSVC 2017, latest update etc.

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [August 26, 2017, 8:33pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/5 "2017-08-26T20:33:00Z")

</div>

This is with the tip and VS2015 on Windows 10 and Parallels 13:

[![](https://dl.dropboxusercontent.com/s/1bghvqdudzohb7e/shadow_1.png?dl=0) ](https://dl.dropboxusercontent.com/s/1bghvqdudzohb7e/shadow_1.png?dl=0)
* * *
[![](https://dl.dropboxusercontent.com/s/4wz6iz4q7fml22m/shadow_2.png?dl=0) ](https://dl.dropboxusercontent.com/s/4wz6iz4q7fml22m/shadow_2.png?dl=0)

This is with:

```
void CLoadTemplateDlg::paint (Graphics& g)
{
    g.setColour (Colours::darkgrey);

    g.setOpacity (0.85f);

    g.fillAll();

    DropShadow ds;
    ds.colour = Colours::white;

    Rectangle<int> workArea;

    workArea.setWidth (m_pWorkArea->getWidth() + 6);
    workArea.setHeight (m_pWorkArea->getHeight() + 6);
    workArea.setCentre (getLocalBounds().getCentre());

    ds.drawForRectangle (g, workArea);
}

```

where m\_pWorkArea is the Component of the dialog with the dropShadow. The screen res. is 2560x1353.

Are you using OpenGL? What’s your graphic card and screen res.?

Rail

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [August 27, 2017, 6:27pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/6 "2017-08-27T18:27:12Z")

</div>

That’s because you set neither a radius nor an offset.

Can you try a radius of 30 and an offset of 0, 10, please?

```
ds.radius = 30;
ds.offset = { 0, 10 };

```

I’ve just tested all combinations and only when there is a radius set AND and offset, then the bug appears.

No, I’m not using OpenGL. My screen-res is 3440 x 1440.

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [August 27, 2017, 7:34pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/7 "2017-08-27T19:34:16Z")

</div>

> [@Toddler-Boy](#):
>
> Can you try a radius of 30 and an offset of 0, 10, please?

With those I see this on both platforms…

[![](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/7/2/72af9ecf9e1b4cf8227db4c13c33436901313382.png) ](https://dl.dropboxusercontent.com/s/znf9x939g1xtwwl/shadow_3.png?dl=0)

Rail

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [August 27, 2017, 11:27pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/8 "2017-08-27T23:27:24Z")

</div>

I’ve just tried again on the retina mac and there it does NOT happen for me. I even took a screenshot and zoomed in, in case I missed the 1 pixel gap, because on a retina screen it’s so tiny, but there was no gap there. It seems as if the transform got rid of it there?

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [August 30, 2017, 11:03am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/9 "2017-08-30T11:03:25Z")

</div>

It has something to do with the following calculation at [`juce_DropShadowEffect.cpp:139`](https://github.com/WeAreROLI/JUCE/blob/858b206553dcccc9c78cb8c337f404ad3888ab54/modules/juce_graphics/effects/juce_DropShadowEffect.cpp#L139):

```
const float radiusInset = (radius + 1) / 2.0f;
const float expandedRadius = radius + radiusInset;

```

If the resulting `expandedRadius*nativeScaleFactor` is not an integral number (where `nativeScaleFactor` is the scale factor of your monitor - so 2 for retina) then the gap seems to appear.

It’s odd because the `drawShadowSection` class use `removeFromLeft`/`removeFromRight` which shouldn’t result in there being a gap.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [September 1, 2017, 3:59am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/10 "2017-09-01T03:59:34Z")

</div>

Any idea how to fix this?

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [September 1, 2017, 8:38am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/11 "2017-09-01T08:38:50Z")

</div>

Removing the `+ 1` in the code works for me but I have a feeling that Jules put it in there for a very good reason. He’s on Holiday at the moment but will be back on Monday. I’ll need to discuss this with him once he is back.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [September 1, 2017, 8:46am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/12 "2017-09-01T08:46:45Z")

</div>

Thanks for the update.

---

<div class="post-metadata">

**Author:** ![GarrettBurnett](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@GarrettBurnett](https://forum.juce.com/u/GarrettBurnett)\
**Post date:** [November 9, 2018, 2:00am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/13 "2018-11-09T02:00:08Z")

</div>

Any update on this?

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [January 27, 2019, 7:25pm UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/14 "2019-01-27T19:25:04Z")

</div>

Any Update?  
Running into the same problem.

---

<div class="post-metadata">

**Author:** ![fuo](https://avatars.discourse-cdn.com/v4/letter/f/ba8739/32.png) [@fuo](https://forum.juce.com/u/fuo)\
**Post date:** [February 26, 2022, 9:13am UTC](https://forum.juce.com/t/bug-in-dropshadow-drawforrectangle/23911/15 "2022-02-26T09:13:37Z")

</div>

Any update on this?
