mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 07:21:51 +00:00
Merge pull request #787 from MihailRis/fix-assets-access-attempts-in-headless-mode
fix: assets access attempts in headless mode leading to segfaults
This commit is contained in:
commit
34b87ac596
5 changed files with 28 additions and 10 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
static debug::Logger logger("stdin-reader");
|
static debug::Logger logger("stdin-cmd");
|
||||||
|
|
||||||
static std::thread reader_thread;
|
static std::thread reader_thread;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -420,10 +420,20 @@ EngineSettings& Engine::getSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Assets* Engine::getAssets() {
|
Assets* Engine::getAssets() {
|
||||||
return assets->getStorage();
|
return assets ? assets->getStorage() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assets& Engine::requireAssets() {
|
||||||
|
if (isHeadless()) {
|
||||||
|
throw std::runtime_error("assets are not available in headless mode");
|
||||||
|
}
|
||||||
|
return *assets->getStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetsLoader& Engine::acquireBackgroundLoader() {
|
AssetsLoader& Engine::acquireBackgroundLoader() {
|
||||||
|
if (isHeadless()) {
|
||||||
|
throw std::runtime_error("assets are not available in headless mode");
|
||||||
|
}
|
||||||
return assets->acquireBackgroundLoader();
|
return assets->acquireBackgroundLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ public:
|
||||||
|
|
||||||
/// @brief Get active assets storage instance
|
/// @brief Get active assets storage instance
|
||||||
Assets* getAssets();
|
Assets* getAssets();
|
||||||
|
Assets& requireAssets();
|
||||||
|
|
||||||
AssetsLoader& acquireBackgroundLoader();
|
AssetsLoader& acquireBackgroundLoader();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
static void load_texture(
|
static void load_texture(
|
||||||
const ubyte* bytes, size_t size, const std::string& destname
|
Assets& assets, const ubyte* bytes, size_t size, const std::string& destname
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
engine->getAssets()->store(png::load_texture(bytes, size), destname);
|
assets.store(png::load_texture(bytes, size), destname);
|
||||||
} catch (const std::runtime_error& err) {
|
} catch (const std::runtime_error& err) {
|
||||||
debug::Logger logger("lua.assetslib");
|
debug::Logger logger("lua.assetslib");
|
||||||
logger.error() << err.what();
|
logger.error() << err.what();
|
||||||
|
|
@ -34,6 +34,8 @@ static int l_request_texture(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_load_texture(lua::State* L) {
|
static int l_load_texture(lua::State* L) {
|
||||||
|
auto& assets = engine->requireAssets();
|
||||||
|
|
||||||
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
|
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
|
||||||
throw std::runtime_error("unsupportd image format");
|
throw std::runtime_error("unsupportd image format");
|
||||||
}
|
}
|
||||||
|
|
@ -47,10 +49,13 @@ static int l_load_texture(lua::State* L) {
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
load_texture(buffer.data(), buffer.size(), lua::require_string(L, 2));
|
load_texture(
|
||||||
|
assets, buffer.data(), buffer.size(), lua::require_string(L, 2)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
auto string = lua::bytearray_as_string(L, 1);
|
auto string = lua::bytearray_as_string(L, 1);
|
||||||
load_texture(
|
load_texture(
|
||||||
|
assets,
|
||||||
reinterpret_cast<const ubyte*>(string.data()),
|
reinterpret_cast<const ubyte*>(string.data()),
|
||||||
string.size(),
|
string.size(),
|
||||||
lua::require_string(L, 2)
|
lua::require_string(L, 2)
|
||||||
|
|
@ -61,13 +66,15 @@ static int l_load_texture(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_parse_model(lua::State* L) {
|
static int l_parse_model(lua::State* L) {
|
||||||
|
auto& assets = engine->requireAssets();
|
||||||
|
|
||||||
auto format = lua::require_lstring(L, 1);
|
auto format = lua::require_lstring(L, 1);
|
||||||
auto string = lua::require_lstring(L, 2);
|
auto string = lua::require_lstring(L, 2);
|
||||||
auto name = lua::require_string(L, 3);
|
auto name = lua::require_string(L, 3);
|
||||||
|
|
||||||
if (format == "xml" || format == "vcm") {
|
if (format == "xml" || format == "vcm") {
|
||||||
auto vcmModel = vcm::parse(name, string, format == "xml");
|
auto vcmModel = vcm::parse(name, string, format == "xml");
|
||||||
engine->getAssets()->store(
|
assets.store(
|
||||||
std::make_unique<model::Model>(std::move(vcmModel.squash())), name
|
std::make_unique<model::Model>(std::move(vcmModel.squash())), name
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -79,7 +86,7 @@ static int l_parse_model(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_to_canvas(lua::State* L) {
|
static int l_to_canvas(lua::State* L) {
|
||||||
auto& assets = *engine->getAssets();
|
auto& assets = engine->requireAssets();
|
||||||
|
|
||||||
auto alias = lua::require_lstring(L, 1);
|
auto alias = lua::require_lstring(L, 1);
|
||||||
size_t sep = alias.rfind(':');
|
size_t sep = alias.rfind(':');
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ using namespace scripting;
|
||||||
static DocumentNode get_document_node_impl(
|
static DocumentNode get_document_node_impl(
|
||||||
lua::State*, const std::string& name, const std::string& nodeName, bool throwable=true
|
lua::State*, const std::string& name, const std::string& nodeName, bool throwable=true
|
||||||
) {
|
) {
|
||||||
auto doc = engine->getAssets()->get<UiDocument>(name);
|
auto doc = engine->requireAssets().get<UiDocument>(name);
|
||||||
if (doc == nullptr) {
|
if (doc == nullptr) {
|
||||||
if (throwable) {
|
if (throwable) {
|
||||||
throw std::runtime_error("document '" + name + "' not found");
|
throw std::runtime_error("document '" + name + "' not found");
|
||||||
|
|
@ -1026,7 +1026,7 @@ static int l_gui_str(lua::State* L) {
|
||||||
|
|
||||||
static int l_gui_reindex(lua::State* L) {
|
static int l_gui_reindex(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
auto doc = engine->getAssets()->get<UiDocument>(name);
|
auto doc = engine->requireAssets().get<UiDocument>(name);
|
||||||
if (doc == nullptr) {
|
if (doc == nullptr) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"document '" + std::string(name) + "' not found"
|
"document '" + std::string(name) + "' not found"
|
||||||
|
|
@ -1124,7 +1124,7 @@ static int l_gui_load_document(lua::State* L) {
|
||||||
engine->getGUI(), std::move(env), alias, filename, filename.string()
|
engine->getGUI(), std::move(env), alias, filename, filename.string()
|
||||||
);
|
);
|
||||||
auto document = documentPtr.get();
|
auto document = documentPtr.get();
|
||||||
engine->getAssets()->store(std::move(documentPtr), alias);
|
engine->requireAssets().store(std::move(documentPtr), alias);
|
||||||
|
|
||||||
// namespace extension
|
// namespace extension
|
||||||
if (lua::istable(L, 4)) {
|
if (lua::istable(L, 4)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue