p8g icon indicating copy to clipboard operation
p8g copied to clipboard

[Bug]: Sketches compiled with Emscripten might run into issue if memory is freed right after run

Open bernhardfritz opened this issue 2 years ago • 0 comments

What went wrong?

Let's assume you have a sketch that makes use of dynamic memory allocation. If you compile such a sketch with Emscripten and free memory right after run, your sketch might not run since run does not block code execution.

Ugly workarounds like can be seen in file sketch.c of https://bernhardfritz.github.io/p8g/examples/quadtree/ are necessary right now, e.g.:

#ifndef __EMSCRIPTEN__
    QuadTree_destroy(&quadTree);
#endif

Expected behavior

Calling run in a sketch compiled with Emscripten should break out of current execution flow by e.g. throwing an exception.

Steps to reproduce

Compile the Quadtree example with Emscripten, and remove the Emscripten specific macros and see the sketch running into a segfault.

bernhardfritz avatar Nov 20 '22 21:11 bernhardfritz