Skip to content

Commit

Permalink
Fix frUpdateWorld() using an invalid value for the initial timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeokkim committed Nov 21, 2024
1 parent e7fbb3b commit 6bc1b27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/ferox.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extern "C" {
/* The major, minor, and the patch release version of this library. */
#define FR_API_VERSION_MAJOR 0
#define FR_API_VERSION_MINOR 9
#define FR_API_VERSION_PATCH 6
#define FR_API_VERSION_PATCH 7

/* The full version string of this library. */
#define FR_API_VERSION \
Expand Down
17 changes: 10 additions & 7 deletions src/external/ferox_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
/* Releases the memory allocated for `arr`. */
#define frReleaseDynArray(arr) \
do { \
free((arr).buffer); \
free((arr).buffer); \
\
((arr).length) = 0; \
((arr).capacity) = 0; \
} while (0)

/* Returns the capacity of `arr`. */
Expand Down Expand Up @@ -118,12 +121,12 @@
((arr).length = newLength)

/* Appends `newValue` at the end of `arr`. */
#define frDynArrayPush(arr, newValue) \
do { \
if ((arr).length >= (arr).capacity) \
frSetDynArrayCapacity((arr), ((arr).capacity << 1)); \
\
(arr).buffer[(arr).length] = (newValue), ++((arr).length); \
#define frDynArrayPush(arr, newValue) \
do { \
if ((arr).length >= (arr).capacity) \
frSetDynArrayCapacity((arr), ((arr).capacity << 1)); \
\
(arr).buffer[(arr).length] = (newValue), (arr).length++; \
} while (0)

/* Swaps the `i`-th value and the `j`-th value of `arr`. */
Expand Down
7 changes: 7 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ void frUpdateWorld(frWorld *w, float dt) {
if (w == NULL || dt <= 0.0f) return;

float currentTime = frGetCurrentTime();

if (w->timestamp <= 0.0f) {
w->timestamp = currentTime;

return;
}

float elapsedTime = currentTime - w->timestamp;

w->timestamp = currentTime, w->accumulator += elapsedTime;
Expand Down

0 comments on commit 6bc1b27

Please sign in to comment.