# Smearing on os x

**URL:** <https://forum.juce.com/t/smearing-on-os-x/1108>\
**Category:** MacOSX and iOS\
**Created:** [October 3, 2006, 9:47pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108 "2006-10-03T21:47:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [October 3, 2006, 9:47pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/1 "2006-10-03T21:47:17Z")

</div>

I have a component that is setAlwaysOnTop(true) and fairly regularly it moves itself.

If I get the cpu usage high (just moving the mouse over other components really fast so they need to repait a lot is enough) then the moving component fails to erase itself as it moves. (Or more likely, the components underneath are not getting their repaint message)

This only happens on Mac OS, not windows.

![](http://rabien.com/image/screenshot.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 4, 2006, 8:40am UTC](https://forum.juce.com/t/smearing-on-os-x/1108/2 "2006-10-04T08:40:12Z")

</div>

Nasty. I expect that it’s not the cpu that’s the factor, but rather that there are lots of separate areas being told to repaint at the same time.

One quick idea, looking at the mac code, is that it might be a floating point rounding error. The HIView repainting is all done in floating point co-ords, and a quick way to test it would be to increase the area in juce\_mac\_Windowing.cpp, line 710, just by adding a pixel, e.g.

` r.origin.x = x - 1;
                r.origin.y = y - 1;
                r.size.width = w + 2;
                r.size.height = h + 2;`

If that sorts it out, then we can try some more elegant rounding on the numbers.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [October 4, 2006, 4:24pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/3 "2006-10-04T16:24:42Z")

</div>

I’m compiling for 10.3, so I changed it just above the line you mentioned. No difference.

I have a work around, after the Component moves, get repaint the parent about 5 pixels around the Component. Seems to work for now.

I have a deadline coming up, so I’m pretty busy, so that’ll have to do for now. I’ll look into it more in the future.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 21, 2006, 7:08pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/4 "2006-12-21T19:08:25Z")

</div>

It’s not a rounding error, it seems as if every once and a while a repaint message gets completely lost.

I’m using the JUCE\_ENABLE\_REPAINT\_DEBUGGING and I’m not seeing any coloured rectangles appear when an artifact is left behind.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 21, 2006, 7:55pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/5 "2006-12-21T19:55:42Z")

</div>

Hmm. That’s bad news because it’s Apple code that manages the paint region. They might have a bug, or maybe some limit on the number of rectangles before it starts ignoring them? I guess the only way to find out would be to make it reproducable, but that’s not easy.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 21, 2006, 7:58pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/6 "2006-12-21T19:58:46Z")

</div>

Ok, so I think the problem is calling repaint from inside paint, which in this thread ([http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=875&highlight=paint+repaint](http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=875&highlight=paint+repaint)), you determined was bad.

So I added a assertion to test for it and it’s getting hit from within juce code.

`void TreeViewContentComponent::paint (Graphics& g)
{
    if (owner->rootItem != 0)
    {
        owner->handleAsyncUpdate();`

causes repaints and components to be resized. I assume resizing in a paint is also bad news. [/url]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 21, 2006, 8:29pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/7 "2006-12-21T20:29:54Z")

</div>

Hmm. Yes, resizing a component from within a paint() would call repaint() indirectly. Seems like the mac must be clearing the dirty region list at the end of the paint callback, and losing any new regions that were added.

I think it might actually be better to say that repaint() is ok in a paint() callback, and to fix the mac implementation so that it works. I’m not on my mac at the moment, but how about this little change to the order in the mac ComponentPeer:

[code] if (context.reduceClipRegion (regionsNeedingRepaint))  
{  
regionsNeedingRepaint.clear();

```
                if (! peer->getComponent()->isOpaque())
                {
                    for (RectangleList::Iterator i (*context.getRawClipRegion()); i.next();)
                    {
                        const Rectangle& r = i.getRectangle();
                        image->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
                    }
                }

                regionsNeedingRepaint.clear();
                peer->clearMaskedRegion();
                peer->handlePaint (context);
            }
            else
            {
                regionsNeedingRepaint.clear();
            }

```

[/code]

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 21, 2006, 8:41pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/8 "2006-12-21T20:41:10Z")

</div>

that seems to have fixed it, thanks

i’ll need to do more testing to say for sure if it is fixed

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 21, 2006, 8:47pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/9 "2006-12-21T20:47:58Z")

</div>

Cool. Fingers crossed…

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 21, 2006, 10:20pm UTC](https://forum.juce.com/t/smearing-on-os-x/1108/10 "2006-12-21T22:20:59Z")

</div>

didn’t fix it, I’m just going to avoid calling repaint in the paint

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:58am UTC](https://forum.juce.com/t/smearing-on-os-x/1108/11 "2017-05-12T09:58:16Z")

</div>


