diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp index 00511d66..bbd4446d 100644 --- a/src/frontend/UiDocument.cpp +++ b/src/frontend/UiDocument.cpp @@ -62,9 +62,11 @@ std::unique_ptr UiDocument::read(int penv, std::string namesp, fs::p const std::string text = files::read_string(file); auto xmldoc = xml::parse(file.u8string(), text); - auto env = penv == -1 ? nullptr : scripting::create_doc_environment(penv, namesp); - scripting::Environment envview {penv == -1 ? 0 : env->getId()}; - gui::UiXmlReader reader(envview); + auto env = penv == -1 + ? std::make_unique(0) + : scripting::create_doc_environment(penv, namesp); + + gui::UiXmlReader reader(*env); InventoryView::createReaders(reader); auto view = reader.readXML( file.u8string(), xmldoc->getRoot() @@ -73,9 +75,9 @@ std::unique_ptr UiDocument::read(int penv, std::string namesp, fs::p uidocscript script {}; auto scriptFile = fs::path(file.u8string()+".lua"); if (fs::is_regular_file(scriptFile)) { - scripting::load_layout_script(envview.getId(), namesp, scriptFile, script); + scripting::load_layout_script(env->getId(), namesp, scriptFile, script); } - return std::make_unique(namesp, script, view, penv == -1 ? nullptr : std::move(env)); + return std::make_unique(namesp, script, view, std::move(env)); } std::shared_ptr UiDocument::readElement(fs::path file) {