mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
fix user component initialization exception handling & fix fatal error on uninitialized component access
This commit is contained in:
parent
4295af15cc
commit
28385f236c
2 changed files with 12 additions and 1 deletions
|
|
@ -148,7 +148,12 @@ void scripting::on_entity_spawn(
|
|||
lua::call(L, 1);
|
||||
}
|
||||
for (auto& component : components) {
|
||||
create_component(L, -1, *component, args, saved);
|
||||
try {
|
||||
create_component(L, -1, *component, args, saved);
|
||||
} catch (const std::runtime_error& err) {
|
||||
logger.error() << "could not to initialize user component "
|
||||
<< component->name << ": " << err.what();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& [packid, pack] : content->getPacks()) {
|
||||
|
|
@ -166,6 +171,9 @@ static void process_entity_callback(
|
|||
const std::string& name,
|
||||
std::function<int(lua::State*)> args
|
||||
) {
|
||||
if (env == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto L = lua::get_main_state();
|
||||
lua::pushenv(L, *env);
|
||||
if (lua::hasfield(L, "__disabled")) {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,9 @@ dv::value Entity::serialize() const {
|
|||
if (!scripts.components.empty()) {
|
||||
auto& compsMap = root.object("comps");
|
||||
for (auto& comp : scripts.components) {
|
||||
if (comp->env == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto data =
|
||||
scripting::get_component_value(comp->env, SAVED_DATA_VARNAME);
|
||||
compsMap[comp->name] = data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue