Describe the bug
I need to pass one-off context pointer to ecs_run_post_frame(), so what I am doing is allocating a value and have the callback free the value once called. This is to achieve something like a lambda capturing some values since run_post_frame only allows function pointers.
My problem is that if the world is finished before the call happens, I get a leak:
To Reproduce
Steps to reproduce the behavior:
flecs::world ecs;
int *a = new int(79);
ecs.run_post_frame(
[](flecs::world_t *w, void *ctx) {
int *a = (int *) ctx;
std::cout << "a = " << *a << std::endl;
delete a;
},
a);
// world destroyed here.
The callback is not invoked and int* a does not get a chance to be freed.
Would it be possible to have an additional optional parameter to ecs_run_post_frame that takes a context free callback? If != NULL, this free-callback would be called after each run_post_frame invocation, and on world fini.
My workaround for now is to call ecs.progress() manually before destroying the world, so these callbacks have a chance and can free the context, but that has other side-effects.
Please let me know if this is bug/enhancement and whether this could be changed (I can open a PR). Thanks.
What actually should happen here is that run_post_frame should throw an error when it's called outside of frame_begin/frame_end (which are called by progress).
Describe the bug I need to pass one-off context pointer to
ecs_run_post_frame()
, so what I am doing is allocating a value and have the callback free the value once called. This is to achieve something like a lambda capturing some values sincerun_post_frame
only allows function pointers.My problem is that if the world is finished before the call happens, I get a leak:
To Reproduce Steps to reproduce the behavior:
The callback is not invoked and
int* a
does not get a chance to be freed.Would it be possible to have an additional optional parameter to
ecs_run_post_frame
that takes a context free callback? If != NULL, this free-callback would be called after eachrun_post_frame
invocation, and on world fini.My workaround for now is to call
ecs.progress()
manually before destroying the world, so these callbacks have a chance and can free the context, but that has other side-effects.Please let me know if this is bug/enhancement and whether this could be changed (I can open a PR). Thanks.