Repaint or not to repaint

In one of my plugins I use a frontUI and a backUI. That requireds a redraw of the GUI. The next part of the code works well with Macs, but the on PC it does not work. On PC I need to close the plugins GUI to control the GUI of the host. When I disable the repaint(): All goes correctly, but the UI is not redrawn. Reaper, W7, Juce V2 latest version. What is the correct way of doing this on a PC?

void EMpTy250AudioProcessorEditor::paint (Graphics& g)

{

    if (BackButton.getToggleState())

    {

        BG=ImageCache::getFromMemory(backside::emt250_backside_png,backside::emt250_backside_pngSize);

        repaint();

    }

    else

    {

        BG=ImageCache::getFromMemory(background::emt250_panel_png,background::emt250_panel_pngSize);

        repaint();

    }

    g.drawImage(BG,0,0,getWidth(),getHeight(),0,0,BG.getWidth(),BG.getHeight());

      

}

Yuck! That has nothing to do with Windows, it should never have worked at all!

Calling repaint() inside a paint() method is never a good plan.. I guess what you were trying to do was to repaint the background when this button changes state? So to do that, you need to call repaint when the button changes state, not when something else happens to get painted! Add a button listener and respond to it by repainting whatever's necessary.

..but even that would be bad practice. You'd be tightly-coupling this background picture to the toggle state of a button, which is muddling your data model with your GUI. The button should talk to your model object, and the thing that draws the background should also talk to the model object, but they should never need to talk to each other.

(Note to self: if I ever design a language, I must remember to make the compiler generate a syntax error if someone fails to leave a space after a comma.. it makes my eyes bleed to read that stuff!)

Thanks a lot, Jules!