ofClear / ofBackground not working as expected

I am getting some strange behavior when I turn off automatic clearing (ofSetBackgroundAuto(false);). I am prepared to believe that I’m doing something wrong, but the behavior seems like a bug.

I refined this down to a simple sketch that draws a new circle in a random location in each pass of the draw loop. There is a noticeable flicker as the circle count increases, which was a little surprising. However, the real buggy behavior is I have it configured to clear the screen when any key is typed. To make it really obvious I also change the circle color.

What I expect: the screen will slowly fill in with little circles of one color. When I press a key, the screen will clear and I will get a new collection of circles in the new color.

What I get: the screen doesn’t clear so I can see circles of both colors. However, it is weirder than just not working – it seems to partially clear. Some circles go away. If I clear enough times in rapid succession I can get it completely clear. At a conceptual level, it looks like we are double buffering and the clear only clears one of them (the flicker also seems to line up with multiple buffers that don’t both have the same information).

I am using a brand new MacBook Pro (M1 Pro) running Monterey, so it could be an untested configuration as well.

Here is my test code:

ofColor currentColor;

void changeColor(){
    currentColor.set(ofRandom(0,255),ofRandom(0,255), ofRandom(0,255) );
    ofBackground(0);
}


//--------------------------------------------------------------
void ofApp::setup(){
    ofSetBackgroundAuto(false);
    ofBackground(0);
    
    changeColor();
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(currentColor);
    ofFill();
    ofDrawCircle(ofRandom(0,ofGetWidth()), ofRandom(0,ofGetHeight()), 3);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    changeColor();
}

It would be great to know if this is a bug or a misapprehension of mine (I am new to OF, but not graphics/code sketching).

check this

I can confirm that turning off double buffering helps. The flicker goes away, and it usually clears now. But I’ll emphasize the usually. I still get glitches where the color changes but the screen doesn’t clear. This does confirm my suspicion that there is something up with the double buffering however.

Actually I will amend that usually to sometimes. Also, I am getting something new which after a little bit older content that had been cleared will reappear and sometimes flicker in and out.

Yeah I’ve tested here and there is something strange happening.
I never seen it before because I usually use an ofFbo as my canvas to draw / accumulate graphics and it works well.
You can open an issue on OF github with your description and test code.

Hey I tried to replicate on an m1 mba out of curiosity and I didn’t see the flickering. So a video might be helpful if you open an issue, if you can manage to capture it.

I wonder if the flickering is related to the macbook pro’s display (promotion, 120hz, hdr, etc).

I have tried tinkering with the display settings to no avail. I also tried an external monitor with no change. I did open an issue – I will see about adding some video.