Bug in DropShadow::drawForRectangle

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

dropshadow_gap

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

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

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

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

Rail

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.

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


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

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.

With those I see this on both platforms…

Rail

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?

It has something to do with the following calculation at juce_DropShadowEffect.cpp:139:

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.

Any idea how to fix this?

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.

1 Like

Thanks for the update.

Any update on this?

Any Update?
Running into the same problem.

Any update on this?