Skip to content

Commit

Permalink
#1166 Fix infinite loop in progress() with integer time types
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Mar 8, 2024
1 parent 638575a commit 9c3a1ba
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 12 deletions.
15 changes: 9 additions & 6 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24107,6 +24107,11 @@ ecs_ftime_t flecs_start_measure_frame(
} else {
/* Best guess */
delta_time = (ecs_ftime_t)1.0 / (ecs_ftime_t)60.0;

if (ECS_EQZERO(delta_time)) {
delta_time = user_delta_time;
break;
}
}
}

Expand Down Expand Up @@ -25232,12 +25237,12 @@ void FlecsAlertsImport(ecs_world_t *world) {
ecs_system(world, {
.entity = ecs_id(MonitorAlerts),
.no_readonly = true,
.interval = 0.5
.interval = (ecs_ftime_t)0.5
});

ecs_system(world, {
.entity = ecs_id(MonitorAlertInstances),
.interval = 0.5
.interval = (ecs_ftime_t)0.5
});
}

Expand Down Expand Up @@ -37017,8 +37022,8 @@ void ecs_world_stats_log(
flecs_counter_print("pipeline rebuilds", t, &s->frame.pipeline_build_count);
flecs_counter_print("systems ran", t, &s->frame.systems_ran);
ecs_trace("");
flecs_metric_print("target FPS", world->info.target_fps);
flecs_metric_print("time scale", world->info.time_scale);
flecs_metric_print("target FPS", (ecs_float_t)world->info.target_fps);
flecs_metric_print("time scale", (ecs_float_t)world->info.time_scale);
ecs_trace("");
flecs_gauge_print("actual FPS", t, &s->performance.fps);
flecs_counter_print("frame time", t, &s->performance.frame_time);
Expand Down Expand Up @@ -67493,8 +67498,6 @@ bool flecs_rule_run_until(
return true;
}
} while (true);

return false;
}

static
Expand Down
4 changes: 2 additions & 2 deletions src/addons/alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,12 @@ void FlecsAlertsImport(ecs_world_t *world) {
ecs_system(world, {
.entity = ecs_id(MonitorAlerts),
.no_readonly = true,
.interval = 0.5
.interval = (ecs_ftime_t)0.5
});

ecs_system(world, {
.entity = ecs_id(MonitorAlertInstances),
.interval = 0.5
.interval = (ecs_ftime_t)0.5
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/addons/rules/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2487,8 +2487,6 @@ bool flecs_rule_run_until(
return true;
}
} while (true);

return false;
}

static
Expand Down
4 changes: 2 additions & 2 deletions src/addons/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,8 @@ void ecs_world_stats_log(
flecs_counter_print("pipeline rebuilds", t, &s->frame.pipeline_build_count);
flecs_counter_print("systems ran", t, &s->frame.systems_ran);
ecs_trace("");
flecs_metric_print("target FPS", world->info.target_fps);
flecs_metric_print("time scale", world->info.time_scale);
flecs_metric_print("target FPS", (ecs_float_t)world->info.target_fps);
flecs_metric_print("time scale", (ecs_float_t)world->info.time_scale);
ecs_trace("");
flecs_gauge_print("actual FPS", t, &s->performance.fps);
flecs_counter_print("frame time", t, &s->performance.frame_time);
Expand Down
5 changes: 5 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,11 @@ ecs_ftime_t flecs_start_measure_frame(
} else {
/* Best guess */
delta_time = (ecs_ftime_t)1.0 / (ecs_ftime_t)60.0;

if (ECS_EQZERO(delta_time)) {
delta_time = user_delta_time;
break;
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/custom_builds/c/int_time_type/include/int_time_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef INT_TIME_TYPE_H
#define INT_TIME_TYPE_H

/* This generated file contains includes for project dependencies */
#include "int_time_type/bake_config.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
)
(.)
.|.
| |
_.--| |--._
.-'; ;`-'& ; `&.
\ & ; & &_/
|"""---...---"""|
\ | | | | | | | /
`---.|.|.|.---'
* This file is generated by bake.lang.c for your convenience. Headers of
* dependencies will automatically show up in this file. Include bake_config.h
* in your main project file. Do not edit! */

#ifndef INT_TIME_TYPE_BAKE_CONFIG_H
#define INT_TIME_TYPE_BAKE_CONFIG_H

/* Headers of public dependencies */
#include "../../deps/flecs.h"

#endif

14 changes: 14 additions & 0 deletions test/custom_builds/c/int_time_type/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "int_time_type",
"type": "application",
"value": {
"public": false,
"use": [
"flecs"
],
"standalone": true
},
"lang.c": {
"defines": ["ecs_ftime_t=int32_t"]
}
}
10 changes: 10 additions & 0 deletions test/custom_builds/c/int_time_type/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <int_time_type.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
ecs_world_t *world = ecs_init_w_args(argc, argv);

ecs_progress(world, 0);

return ecs_fini(world);
}

0 comments on commit 9c3a1ba

Please sign in to comment.