flecs-hub / flecs-systems-sdl2

SDL-based renderer for flecs
MIT License
8 stars 5 forks source link

Expected constant expression #2

Open tang1024 opened 4 years ago

tang1024 commented 4 years ago

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);

SanderMertens commented 4 years ago

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.