Weird things happening with framerate


#1

Hi friends,
while playing with of0.10 with Qt creator 4.6.1 and Ubuntu 18.04 I came across some weird behavior that I am not able to explain.

Starting from a new blank project the doe is like this:

//--------------------------------------------------------------
void ofApp::setup(){
    font.load("Helvetica", 16);

    ofSetFrameRate(60);
    ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
    static float currentX = 40;
    static float delta = 2;

    ofSetColor(ofColor::crimson);
    font.drawString("Frame rate test: " + ofToString(ofGetFrameRate(), 1), 20, 50);

    // ofLogNotice() << ofGetFrameRate();

    ofSetColor(ofColor::aliceBlue);
    ofDrawCircle(currentX, 150, 10);

    currentX += delta;

    if(currentX > 280 || currentX < 40)
    {
        delta = -delta;
    }
}

font is defined in ofApp.h as an instance of ofTrueTypeFont, nothing fancy.

What happens is that when I make the of windows quite small, at 320 x 200, the framerate drops randomly drops to 41 - 42 then slowly goes back to 60 and so on. It is not just a matter of measuring it since the small moving circle does noticeable jumps and slows down when fr is lower.

If I remove the // comment mark from the ofLogNotice() line then everything runs smooth @ 60 fps while inside Qt Creator, but not if the app is launched from the console.

Setting window size to something larger (640 x 200 is enough) also solves the problem.

Of course this is not an end-of-the-world tragedy, but I’d like to know what’s happening.

ciao
Davide

Edit: I forgot to mention that Ubuntu is running as a VM inside a OSX host. Memory and CPU usage is always very low even when framerate drops.


#2

not sure what might be going on but don’t use ofSetFrameRate(60); in combination with ofSetVerticalSync(true); vsync already adjusts the framerate and using set framerate might make the app sleep some frames using the system timer which in a virtual machine can be quite unprecise

Also in general inside a vm you can’t expect things to run super smoothly


#3

Yes it was there just for testing, adding or removing it did not change anything. May be as you say the problem is related to the VM… never mind, I was just curious about its randomness.