From 6bc1b272ba3c53f8f6396a7060f9e4c824a0399c Mon Sep 17 00:00:00 2001 From: jdeokkim Date: Thu, 21 Nov 2024 12:57:37 +0900 Subject: [PATCH] Fix `frUpdateWorld()` using an invalid value for the initial `timestamp` --- include/ferox.h | 2 +- src/external/ferox_utils.h | 17 ++++++++++------- src/world.c | 7 +++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/ferox.h b/include/ferox.h index 936618a..08c234d 100644 --- a/include/ferox.h +++ b/include/ferox.h @@ -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 \ diff --git a/src/external/ferox_utils.h b/src/external/ferox_utils.h index af9dcb8..5009850 100644 --- a/src/external/ferox_utils.h +++ b/src/external/ferox_utils.h @@ -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`. */ @@ -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`. */ diff --git a/src/world.c b/src/world.c index a48f28f..c7cb818 100644 --- a/src/world.c +++ b/src/world.c @@ -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;