flecs-hub/flecs-systems-sdl2

Expected constant expression

tang1024 opened this issue · 1 comments

Found a bug when compiling the source.

Location
Line 96, flecs-systems-sdl2/src/render.c

Bug
uint8_t point_count = shape->point_count;
ecs_assert(point_count <= 8, ECS_INVALID_PARAMETER, NULL);
EcsPoint2D points[point_count]; // <<< dynamic c variable but static c array; however, point_count is not determined at compile time; use dynamic array instead

Easy Fix
EcsPoint2D* points = malloc(point_count * sizeof(points[0]));
free(points);

Similarly,
Sint16* gfx_x = malloc(point_count * sizeof(gfx_x[0]));
Sint16* gfx_y = malloc(point_count * sizeof(gfx_y[0]));
free(gfx_x);
free(gfx_y);

Hi @tang1024, thanks for reporting the issue!

This is a "variable sized array" which was added in C99, but unfortunately not supported by msvc. I'll update the code to use something else.