fix segfault at attempt to create/open world when another is open

This commit is contained in:
MihailRis 2025-01-13 02:52:59 +03:00
parent 5130907192
commit 390d54c212
2 changed files with 7 additions and 2 deletions

View File

@ -70,7 +70,7 @@ void ServerMainloop::run() {
begin = system_clock::now(); begin = system_clock::now();
} }
} }
logger.info() << "test finished"; logger.info() << "script finished";
} }
void ServerMainloop::setLevel(std::unique_ptr<Level> level) { void ServerMainloop::setLevel(std::unique_ptr<Level> level) {

View File

@ -55,6 +55,9 @@ static int l_new_world(lua::State* L) {
auto name = lua::require_string(L, 1); auto name = lua::require_string(L, 1);
auto seed = lua::require_string(L, 2); auto seed = lua::require_string(L, 2);
auto generator = lua::require_string(L, 3); auto generator = lua::require_string(L, 3);
if (level != nullptr) {
throw std::runtime_error("world must be closed before");
}
auto controller = engine->getController(); auto controller = engine->getController();
controller->createWorld(name, seed, generator); controller->createWorld(name, seed, generator);
return 0; return 0;
@ -64,7 +67,9 @@ static int l_new_world(lua::State* L) {
/// @param name Name world /// @param name Name world
static int l_open_world(lua::State* L) { static int l_open_world(lua::State* L) {
auto name = lua::require_string(L, 1); auto name = lua::require_string(L, 1);
if (level != nullptr) {
throw std::runtime_error("world must be closed before");
}
auto controller = engine->getController(); auto controller = engine->getController();
controller->openWorld(name, false); controller->openWorld(name, false);
return 0; return 0;