# Does VBlankAttachment cause repaint whole parent component?

**URL:** https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184
**Category:** General JUCE discussion
**Created:** [November 12, 2024, 10:22pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184 "2024-11-12T22:22:22Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)
#### Post date: [November 12, 2024, 10:22pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/1 "2024-11-12T22:22:22Z")

</div>

Hello,

My `VBlankAttachment` causes repainting whole parent `Component`, even the area which is not marked as “dirty” in `repaint()` and even though the “dirty” area is opaque. Is it normal behaviour? Or do I do something wrong?

I have plugin which has two main components.

One is remote panel (`mainViewComponent`) with standard plugin components like sliders, buttons etc. And that one is repainted only when needed.  
And another one is frequency analyser (`analyserViewComponent`) which uses `VBlankAttachment` for smooth painting.

The problem is that when I set `analyserViewComponent.setVisible(true);` then `VBlankAttachment` causes repainting also `mainViewComponent` which I don’t need to and actually it is pain in the ass, because `mainViewComponent::paint()` is quite heavy and I don’t need to repaint it if not needed.

I set both components to `setOpaque(true);` and of course both components fill all bounds with solid colour. In addition both component doesn’t overlap each other.

Does anyone know what could cause such issue?

In more details the plugin works as follows:  
Frequency analyser can be toggle on/off. When off then the whole component is set to `setVisible(false);`, and its `VBlankAttachment` is destroyed and whole plugin editor is resized to bounds required only for `mainViewComponent`. And then everything works fine (`mainViewComponent` is repainted only when required).

But when analyser is toggled on, then editor is resized to bounds required for both components so no one component overlaps another one. `VBlankAttachment` is set as follows:

`this->vBlankAttachment = { this, [this]() { this->repaint(); }};`

Where `this` is of course pointer to `analyserViewComponent`.

For any help great thanks in advance.  
Best regards.

---

<div class="post-metadata">

### Author: ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)
#### Post date: [November 13, 2024, 7:45pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/2 "2024-11-13T19:45:00Z")

</div>

OK, I found what causes my issue. I will try to explain if anyone has similar issue.

Unfortunately in my case there is no good solution. I have asctually two components which use `VBlankAttachment`. The fft analyser and level meter which is located on remote component. Even though level meter takes only small area part of the whole parent component the issue is because of composition (layout) of level meter and fft analyser which looks as follows:

 ![repeinting area](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/f/c/fc07dfc813dea8c80676368bab8aa2143fb6ed95.png)

So even though I call repaint only for orange components, the parent component does not draw list of rectangles but only single rectangle area (white frame) in which both orange repainted components can be fit.

So it looks like the only solution is to change the layout of components.

---

<div class="post-metadata">

### Author: ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)
#### Post date: [November 14, 2024, 8:58pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/3 "2024-11-14T20:58:09Z")

</div>

Hi there, I don’t think this has to do with the VBlankAttachment. I would expect the same to happen if you called `repaint()` using a timer.

You could try calling `setBufferedToImage (true)` on the remote panel. But for this to work the remote panel should not have children that will constantly get repainted. Turn it into a separate component. Add it, as well as the the level meter and the fft analyser, as children to the main view component. That way the remote panel, the fft analyser and the level meter are all siblings.

And, if on macOS, you could try the preprocessor definition `JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS=1`

Hope this helps!

---

<div class="post-metadata">

### Author: ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)
#### Post date: [November 15, 2024, 2:52pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/4 "2024-11-15T14:52:04Z")

</div>

Thanks aamf. Yes, you are right that described issue has nothing to do with VBlankAttachment. I forgot to mention about that in my own answer 🙂

But I have question to mentioned by you `setBufferedToImage(true)`.  
I try to understand it, what exactly it does. In [documentation](https://docs.juce.com/master/classComponent.html#af19bbc2186e3297ddd55c328e46c014b) they say something like:

> …so that when asked to redraw itself, it can use this buffer rather than actually calling the paint() method

I want avoid repainting if it is unnecessary. But it looks like it `setBufferedToImage(true)` causes that component is still repainted (even if not needed) but doesn’t call `paint()` method. So what in case if in my `paint()` method there is code that is lighter for rendering than painting buffered image? Does it make a sense to use `setBufferedToImage(true)` in such scenario?

By the way I am not sure if such case is even possible but my point is to ask if `setBufferedToImage(true)` will cause avoiding refreshing that part of screen which is ocupated by that `Component`.

I suppose it can be stupid question but I am not familiar in rendering, graphic cards etc.

---

<div class="post-metadata">

### Author: ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)
#### Post date: [November 15, 2024, 7:21pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/5 "2024-11-15T19:21:16Z")

</div>

> [@pajczur](#):
>
> So what in case if in my `paint()` method there is code that is lighter for rendering than painting buffered image? Does it make a sense to use `setBufferedToImage(true)` in such scenario?

No, in that case it will hot help.

Not sure I can answer the other questions though.

---

<div class="post-metadata">

### Author: ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)
#### Post date: [November 15, 2024, 7:34pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/6 "2024-11-15T19:34:48Z")

</div>

> [@aamf](#):
>
> And, if on macOS, you could try the preprocessor definition `JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS=1`

@pajczur - are you on MacOS? This will almost definitely fix it. I had an issue where two LEDs on opposite sides of the GUI that happened to blink at the same time were refreshing the entire rectangle between them. This fixed it.

---

<div class="post-metadata">

### Author: ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)
#### Post date: [November 16, 2024, 5:34pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/7 "2024-11-16T17:34:29Z")

</div>

@stephenk - how did you find out that the rectangle in between was being refreshed? By enabling repaint debugging, checking if repaint() was being called, profiling… ?

---

<div class="post-metadata">

### Author: ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)
#### Post date: [November 16, 2024, 7:57pm UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/8 "2024-11-16T19:57:03Z")

</div>

> [@aamf](#):
>
> how did you find out that the rectangle in between was being refreshed?

@aamf - It was a while ago, but from some notes I made at the time:

I was able to prove this by putting this code in ComponentPeer::handlePaint(), in the JUCE\_ENABLE\_REPAINT\_DEBUGGING section right after the g.FillAll(), to show the bounds of the clipRectangle. (JUCE\_ENABLE\_REPAINT\_DEBUGGING must be enabled, but you can comment out the g.FillAll())

```auto
    // TEMPORARY_EDIT
    auto r = g.getClipBounds();
    std::cerr << String::formatted("bounds x %03d, y %03d, w %03d, h %03d", 
			r.getX(), r.getY(), r.getWidth(), r. getHeight()) << "\n";

```

This lets us see the actual regions that are called to repaint, which JUCE\_ENABLE\_REPAINT\_DEBUGGING does not display correctly.

See also:

> [@Mac OSX: painting two small child components far apart invalidates entire area between](https://forum.juce.com/t/mac-osx-painting-two-small-child-components-far-apart-invalidates-entire-area-between/46584):
>
> I have two “flashing LEDs” - one in the upper left is a Tempo LED that blinks on the beat, while tiny ones in the lower right are Pattern LEDs that track the steps of a pattern through a step-editing grid. As the Pattern LEDs are being driven by some subdivision of the tempo, they blink/change more often than the Tempo Led, like 4:1 as an example. What happens is that when the the Tempo LED and a Pattern LED happen to execute a paint at the same time, even though one is in the upper left and o…

---

<div class="post-metadata">

### Author: ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)
#### Post date: [November 17, 2024, 5:56am UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/9 "2024-11-17T05:56:52Z")

</div>

Ah, very interesting. Thank you!

---

<div class="post-metadata">

### Author: ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)
#### Post date: [April 11, 2025, 12:23am UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/10 "2025-04-11T00:23:37Z")

</div>

> …are you on MacOS? This will almost definitely fix it.

Yes I’ve just tested. Preprocessor definition `JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS=1` fix it on Mac. But actually my client reported issue on Windows. So I need to find some good solution which would work on Windows too.

---

<div class="post-metadata">

### Author: ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)
#### Post date: [April 11, 2025, 5:59am UTC](https://forum.juce.com/t/does-vblankattachment-cause-repaint-whole-parent-component/64184/11 "2025-04-11T05:59:37Z")

</div>

I’ve not seen it reported that Windows had this same exact problem, in the same way… My Windows version did not have the same problem as the Mac version. Maybe it’s something else…
