#2295·flecs

Re-entering scope of anonymous entity through variable in managed script asserts when script is updated

Author: b-dekuCreated Sep 27, 2026Updated Sep 28, 2026
Labelsbug

Describe the bug The following script:

const root = new root {}
$root {}

when run as a managed script, will result in an assert upon trying to update the script:

fatal: entity.c: 2667: assert(!current): invalid call to make_alive(): entity 520 is alive with different generation (1 vs 0) (INVALID_OPERATION)
build/FlecsSandbox(+0x77140) [0x64690214a140]
build/FlecsSandbox(+0x169b7) [0x6469020e99b7]
build/FlecsSandbox(+0x178a5) [0x6469020ea8a5]
build/FlecsSandbox(+0x17a86) [0x6469020eaa86]
build/FlecsSandbox(+0x16c9f) [0x6469020e9c9f]
build/FlecsSandbox(+0x520f5) [0x6469021250f5]
build/FlecsSandbox(+0x509ad) [0x6469021239ad]
build/FlecsSandbox(+0xf26e3) [0x6469021c56e3]
build/FlecsSandbox(+0xf2a3e) [0x6469021c5a3e]
build/FlecsSandbox(+0xf3583) [0x6469021c6583]
build/FlecsSandbox(+0xf982a) [0x6469021cc82a]
build/FlecsSandbox(+0xf8141) [0x6469021cb141]
build/FlecsSandbox(+0xf8083) [0x6469021cb083]
build/FlecsSandbox(+0xf8dba) [0x6469021cbdba]
build/FlecsSandbox(+0x3a1f1) [0x64690210d1f1]
build/FlecsSandbox(+0x3a9d2) [0x64690210d9d2]
build/FlecsSandbox(+0x6e60) [0x6469020d9e60]
build/FlecsSandbox(+0x679a) [0x6469020d979a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2a1ca) [0x7d11c882a1ca]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x8b) [0x7d11c882a28b]
build/FlecsSandbox(+0x6625) [0x6469020d9625]

Note this works without issue the first run. It seems the generation is not updated when resolving the interpolated string for anonymous entities when the script is rerun.

This works fine if the entity is named (e.g

const root = new foo {}
$root {}

To Reproduce

cpp
#include "flecs.h"

auto main(int argc, char *argv[]) -> int {
  flecs::world ecs;

  auto managed = R"(
    const root = new {}
    $root {}
  )";

  auto managed_script = ecs.script().code(managed).run();
  ecs.script_update(managed_script, managed);

  return 0;
}

Expected behavior Opening the scope again this way should not assert.

Additional context

Tested on latest master (9e874bca2c05b60612cf5b671988adefc0785820).