Skip to content

Commit

Permalink
#473 fix issue with calling ecs_get_object from stage
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Aug 16, 2021
1 parent dd26b01 commit 5719c63
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
2 changes: 2 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8062,6 +8062,8 @@ ecs_entity_t ecs_get_object(
ecs_assert(world != NULL, ECS_INVALID_PARAMETER, NULL);
ecs_assert(rel != 0, ECS_INVALID_PARAMETER, NULL);

world = ecs_get_world(world);

if (!entity) {
return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1924,14 +1924,14 @@ void ecs_os_set_api_defaults(void);
#define ecs_os_alloca(size) alloca((size_t)(size))
#endif

#define ecs_os_malloc_t(T) (T*)(ecs_os_malloc(ECS_SIZEOF(T)))
#define ecs_os_malloc_n(T, count) (T*)(ecs_os_malloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_calloc_t(T) (T*)(ecs_os_calloc(ECS_SIZEOF(T)))
#define ecs_os_calloc_n(T, count) (T*)(ecs_os_calloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_realloc_t(ptr, T) (T*)(ecs_os_realloc([ptr, ECS_SIZEOF(T)))
#define ecs_os_realloc_n(ptr, T, count) (T*)(ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
#define ecs_os_alloca_t(T) (T*)(ecs_os_alloca(ECS_SIZEOF(T)))
#define ecs_os_alloca_n(T, count) (T*)(ecs_os_alloca(ECS_SIZEOF(T) * (count)))
#define ecs_os_malloc_t(T) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
#define ecs_os_malloc_n(T, count) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_calloc_t(T) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
#define ecs_os_calloc_n(T, count) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_realloc_t(ptr, T) ECS_CAST(T*, ecs_os_realloc([ptr, ECS_SIZEOF(T)))
#define ecs_os_realloc_n(ptr, T, count) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
#define ecs_os_alloca_t(T) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
#define ecs_os_alloca_n(T, count) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))

/* Strings */
#ifndef ecs_os_strdup
Expand Down
16 changes: 8 additions & 8 deletions include/flecs/os_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ void ecs_os_set_api_defaults(void);
#define ecs_os_alloca(size) alloca((size_t)(size))
#endif

#define ecs_os_malloc_t(T) (T*)(ecs_os_malloc(ECS_SIZEOF(T)))
#define ecs_os_malloc_n(T, count) (T*)(ecs_os_malloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_calloc_t(T) (T*)(ecs_os_calloc(ECS_SIZEOF(T)))
#define ecs_os_calloc_n(T, count) (T*)(ecs_os_calloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_realloc_t(ptr, T) (T*)(ecs_os_realloc([ptr, ECS_SIZEOF(T)))
#define ecs_os_realloc_n(ptr, T, count) (T*)(ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
#define ecs_os_alloca_t(T) (T*)(ecs_os_alloca(ECS_SIZEOF(T)))
#define ecs_os_alloca_n(T, count) (T*)(ecs_os_alloca(ECS_SIZEOF(T) * (count)))
#define ecs_os_malloc_t(T) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
#define ecs_os_malloc_n(T, count) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_calloc_t(T) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
#define ecs_os_calloc_n(T, count) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_realloc_t(ptr, T) ECS_CAST(T*, ecs_os_realloc([ptr, ECS_SIZEOF(T)))
#define ecs_os_realloc_n(ptr, T, count) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
#define ecs_os_alloca_t(T) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
#define ecs_os_alloca_n(T, count) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))

/* Strings */
#ifndef ecs_os_strdup
Expand Down
2 changes: 2 additions & 0 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,8 @@ ecs_entity_t ecs_get_object(
ecs_assert(world != NULL, ECS_INVALID_PARAMETER, NULL);
ecs_assert(rel != 0, ECS_INVALID_PARAMETER, NULL);

world = ecs_get_world(world);

if (!entity) {
return 0;
}
Expand Down
19 changes: 18 additions & 1 deletion test/api/src/SingleThreadStaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2948,5 +2948,22 @@ void SingleThreadStaging_get_case_from_stage() {
}

void SingleThreadStaging_get_object_from_stage() {
// Implement testcase
ecs_world_t *world = ecs_init();

ECS_TAG(world, CaseOne);
ECS_TAG(world, CaseTwo);
ECS_TYPE(world, Switch, CaseOne, CaseTwo);

ecs_entity_t parent = ecs_new_id(world);
ecs_entity_t e = ecs_new_w_pair(world, EcsChildOf, parent);

ecs_staging_begin(world);

ecs_world_t *stage = ecs_get_stage(world, 0);

test_assert(parent == ecs_get_object(stage, e, EcsChildOf, 0));

ecs_staging_end(world);

ecs_fini(world);
}

0 comments on commit 5719c63

Please sign in to comment.