ofTimer nanoseconds values

#1

Hi!

I’m trying to use ofTimer, as the example provided in the documentation.

When I setPeriodicEvent to 1 nano second or lower, everything runs as expected.
If I go over that value, it just runs as fast as it can.

uint64_t nanoseconds = 1000000000; // One second, OK
uint64_t nanoseconds = 500000000; // Half-second, OK
uint64_t nanoseconds = 2000000000; // Two seconds, NOT OK

What am I missing?

(macOS 10.13.6, OF 0.10.1, Xcode 10.1, debug and released, no changes to build settings)

#2

Just tested this and it works fine for me, perhaps post the code you are trying to run so we can see where’s the problem

#3
class ofxWebScrapper: public ofThread
{
public:
    ofxWebScrapper();
    ~ofxWebScrapper();
    
private:
    void threadedFunction();
    ofTimer timer;
};

ofxWebScrapper::ofxWebScrapper()
{
//    uint64_t nanoseconds = 1000000000; // One second, OK
//    uint64_t nanoseconds = 500000000; // Half-second, OK
    uint64_t nanoseconds = 2000000000; // Two seconds, NOT OK
    
    timer.setPeriodicEvent(nanoseconds);
    startThread();
}

ofxWebScrapper::~ofxWebScrapper()
{
    waitForThread(true);
}

void ofxWebScrapper::threadedFunction()
{
    while(isThreadRunning())
    {
        timer.waitNext();
        cout << "Ping..." << "\n";
    }
}

Of course, totally forgot. In the meanwhile I was able to run the code above with no issues on Window 10, OF 0.9.8 and on another Mac with OF 0.9.8. But the same new Mac on OF 0.10.1, also buggy.

Checked the source, and saw that the OF team made a few changes. Haven’t got the time to actually do something. Maybe tonight.

#4

I did fix some problems with ofTimer from 0.9 to 0.10 but not sure how that would break it on mac alone. might be related with the new time functions. does it fail in windows too or only in mac?

#5

Okay, so:

Windows OF 0.9.8: OK
Windows OF 0.10.1: OK

MacOS OF 0.9.8: OK
MacOS OF 0.10.1: FAIL

#6

can you open an issue on github?

#7

actually no worries, this is now fixed in master and will be in today’s nightly builds. This is the fix:

1 Like
#8

Ahahahah! Nice! ( :
In the meanwhile I’ve open this.