diff --git a/distr/flecs.c b/distr/flecs.c index 663627cad..e16314453 100644 --- a/distr/flecs.c +++ b/distr/flecs.c @@ -57789,6 +57789,9 @@ int ecs_script_update( ecs_entity_t prev = ecs_set_with(world, flecs_script_tag(e, instance)); if (ecs_script_eval(s->script, NULL)) { + ecs_script_free(s->script); + s->script = NULL; + ecs_delete_with(world, ecs_pair_t(EcsScript, e)); result = -1; } diff --git a/src/addons/script/script.c b/src/addons/script/script.c index a1163c5ca..206623242 100644 --- a/src/addons/script/script.c +++ b/src/addons/script/script.c @@ -173,6 +173,9 @@ int ecs_script_update( ecs_entity_t prev = ecs_set_with(world, flecs_script_tag(e, instance)); if (ecs_script_eval(s->script, NULL)) { + ecs_script_free(s->script); + s->script = NULL; + ecs_delete_with(world, ecs_pair_t(EcsScript, e)); result = -1; } diff --git a/test/script/project.json b/test/script/project.json index 0500317d9..0e0a6cf20 100644 --- a/test/script/project.json +++ b/test/script/project.json @@ -387,7 +387,9 @@ "update_template_after_error", "template_in_template", "unterminated_binary", - "component_in_with_scope" + "component_in_with_scope", + "reload_script_w_component_w_error", + "reload_script_w_component_w_error_again" ] }, { "id": "Expr", diff --git a/test/script/src/Error.c b/test/script/src/Error.c index 39734d195..31bdabb3a 100644 --- a/test/script/src/Error.c +++ b/test/script/src/Error.c @@ -1239,3 +1239,86 @@ void Error_unterminated_binary(void) { ecs_fini(world); } + +void Error_reload_script_w_component_w_error(void) { + ecs_world_t *world = ecs_init(); + + ecs_entity_t s = ecs_script(world, { + .code = + "struct Position {\n" + " x = f32\n" + " y = f32\n" + "}\n" + "\n" + "e {\n" + " Position: {10, 20}\n" + "}\n" + }); + + test_assert(s != 0); + + ecs_log_set_level(-4); + + test_assert(0 != ecs_script_update(world, s, 0, + "struct Position {\n" + " x = f32\n" + " y = f32\n" + "}\n" + "\n" + "e {\n" + " Position: {10, 20}\n" + "}\n" + "\n" + "f\n" + )); + + ecs_fini(world); +} + +void Error_reload_script_w_component_w_error_again(void) { + ecs_world_t *world = ecs_init(); + + ecs_entity_t s = ecs_script(world, { + .code = + "struct Position {\n" + " x = f32\n" + " y = f32\n" + "}\n" + "\n" + "e {\n" + " Position: {10, 20}\n" + "}\n" + }); + + test_assert(s != 0); + + ecs_log_set_level(-4); + + test_assert(0 != ecs_script_update(world, s, 0, + "struct Position {\n" + " x = f32\n" + " y = f32\n" + "}\n" + "\n" + "e {\n" + " Position: {10, 20}\n" + "}\n" + "\n" + "f\n" + )); + + ecs_log_set_level(-1); + + test_assert(0 == ecs_script_update(world, s, 0, + "struct Position {\n" + " x = f32\n" + " y = f32\n" + "}\n" + "\n" + "e {\n" + " Position: {10, 20}\n" + "}\n" + )); + + ecs_fini(world); +} diff --git a/test/script/src/main.c b/test/script/src/main.c index 7fa123738..4d2792fde 100644 --- a/test/script/src/main.c +++ b/test/script/src/main.c @@ -380,6 +380,8 @@ void Error_update_template_after_error(void); void Error_template_in_template(void); void Error_unterminated_binary(void); void Error_component_in_with_scope(void); +void Error_reload_script_w_component_w_error(void); +void Error_reload_script_w_component_w_error_again(void); // Testsuite 'Expr' void Expr_setup(void); @@ -2210,6 +2212,14 @@ bake_test_case Error_testcases[] = { { "component_in_with_scope", Error_component_in_with_scope + }, + { + "reload_script_w_component_w_error", + Error_reload_script_w_component_w_error + }, + { + "reload_script_w_component_w_error_again", + Error_reload_script_w_component_w_error_again } }; @@ -3633,7 +3643,7 @@ static bake_test_suite suites[] = { "Error", NULL, NULL, - 65, + 67, Error_testcases }, {