victorfisac / Physac

2D physics header-only library for videogames developed in C using raylib library.

Home Page:http://www.victorfisac.com/physac

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initialize frequency to a different value

filipencopav opened this issue · comments

I asked this question and we seem to have found out a bug:

In the GetCurrentTime() function there is this bit of code:

...
    return (double)(GetTimeCount() - baseTime)/frequency*1000;
...

Frequency get initialized when InitTimer() is called, but there is a snip that might fail and it would remain 0:

#if defined(__linux__)
    struct timespec now;
    if (clock_gettime(CLOCK_MONOTONIC, &now) == 0)
        frequency = 1000000000;
#endif

on linux, if clock_gettime() fails, frequency will remain 0, which will cause a division by 0 in GetCurrentTime()

Maybe initialize it with 1?