diff --git a/include/openspace/rendering/loadingscreen.h b/include/openspace/rendering/loadingscreen.h index 1ae6525a85..8870f9ac59 100644 --- a/include/openspace/rendering/loadingscreen.h +++ b/include/openspace/rendering/loadingscreen.h @@ -51,6 +51,7 @@ public: using ShowMessage = ghoul::Boolean; using ShowNodeNames = ghoul::Boolean; using ShowProgressbar = ghoul::Boolean; + using CatastrophicError = ghoul::Boolean; LoadingScreen(ShowMessage showMessage, ShowNodeNames showNodeNames, ShowProgressbar showProgressbar); @@ -59,6 +60,7 @@ public: void render(); void postMessage(std::string message); + void setCatastrophicError(CatastrophicError catastrophicError); void finalize(); @@ -110,6 +112,7 @@ private: GLuint vboBox; } _progressbar; + bool _hasCatastrophicErrorOccurred; std::string _message; std::mutex _messageMutex; @@ -118,9 +121,6 @@ private: ItemStatus status; bool hasLocation; -#ifdef LOADINGSCREEN_DEBUGGING - bool exhaustedSearch; -#endif // LOADINGSCREEN_DEBUGGING glm::vec2 ll; glm::vec2 ur; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9d0809cf5a..47267f22f9 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -576,12 +576,14 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { } ); + bool errorWithPreInit = false; // Run start up scripts try { runPreInitializationScripts(scenePath); } catch (const ghoul::RuntimeError& e) { LERRORC(e.component, e.message); + errorWithPreInit = true; } Scene* scene; @@ -622,60 +624,68 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { // an OpenGL context std::atomic_bool initializeFinished(false); bool errorWhileLoading = false; - std::thread t([&scene, scenePath, &initializeFinished, &errorWhileLoading, this]() { - _loadingScreen->postMessage("Creating scene..."); - _loadingScreen->setPhase(LoadingScreen::Phase::Construction); - try { - scene = _sceneManager->loadScene(scenePath); - } - catch (const ghoul::FileNotFoundError& e) { - LERRORC(e.component, e.message); - errorWhileLoading = true; - return; - } - catch (const Scene::InvalidSceneError& e) { - LERRORC(e.component, e.message); - errorWhileLoading = true; - return; - } - catch (const ghoul::RuntimeError& e) { - LERRORC(e.component, e.message); - errorWhileLoading = true; - return; - } - catch (const std::exception& e) { - LERROR(e.what()); - errorWhileLoading = true; - return; - } - catch (...) { - LERROR("Unknown error loading the scene"); - errorWhileLoading = true; - return; + std::thread t([&scene, scenePath, &initializeFinished, &errorWhileLoading, + &errorWithPreInit, this]() + { + if (errorWithPreInit) { + _loadingScreen->postMessage("Failed loading scene '" + scenePath + "'"); + _loadingScreen->setCatastrophicError(LoadingScreen::CatastrophicError::Yes); } + else { + _loadingScreen->postMessage("Creating scene..."); + _loadingScreen->setPhase(LoadingScreen::Phase::Construction); + try { + scene = _sceneManager->loadScene(scenePath); + } + catch (const ghoul::FileNotFoundError& e) { + LERRORC(e.component, e.message); + errorWhileLoading = true; + return; + } + catch (const Scene::InvalidSceneError& e) { + LERRORC(e.component, e.message); + errorWhileLoading = true; + return; + } + catch (const ghoul::RuntimeError& e) { + LERRORC(e.component, e.message); + errorWhileLoading = true; + return; + } + catch (const std::exception& e) { + LERROR(e.what()); + errorWhileLoading = true; + return; + } + catch (...) { + LERROR("Unknown error loading the scene"); + errorWhileLoading = true; + return; + } - Scene* previousScene = _renderEngine->scene(); - if (previousScene) { - _syncEngine->removeSyncables(_timeManager->getSyncables()); - _syncEngine->removeSyncables(_renderEngine->getSyncables()); - _syncEngine->removeSyncable(_scriptEngine.get()); + Scene* previousScene = _renderEngine->scene(); + if (previousScene) { + _syncEngine->removeSyncables(_timeManager->getSyncables()); + _syncEngine->removeSyncables(_renderEngine->getSyncables()); + _syncEngine->removeSyncable(_scriptEngine.get()); - _renderEngine->setScene(nullptr); - _renderEngine->setCamera(nullptr); - _sceneManager->unloadScene(*previousScene); + _renderEngine->setScene(nullptr); + _renderEngine->setCamera(nullptr); + _sceneManager->unloadScene(*previousScene); + } + + // Initialize the RenderEngine + _renderEngine->setScene(scene); + _renderEngine->setCamera(scene->camera()); + _renderEngine->setGlobalBlackOutFactor(0.0); + _renderEngine->startFading(1, 3.0); + + _loadingScreen->setPhase(LoadingScreen::Phase::Initialization); + + scene->initialize(); + _loadingScreen->postMessage("Finished initializing"); + initializeFinished = true; } - - // Initialize the RenderEngine - _renderEngine->setScene(scene); - _renderEngine->setCamera(scene->camera()); - _renderEngine->setGlobalBlackOutFactor(0.0); - _renderEngine->startFading(1, 3.0); - - _loadingScreen->setPhase(LoadingScreen::Phase::Initialization); - - scene->initialize(); - _loadingScreen->postMessage("Finished initializing"); - initializeFinished = true; }); // While the SceneGraphNodes initialize themselves, we can hand over control to the @@ -1433,12 +1443,10 @@ void OpenSpaceEngine::externalControlCallback(const char* receivedChars, int siz void OpenSpaceEngine::toggleShutdownMode() { if (_shutdown.inShutdown) { // If we are already in shutdown mode, we want to disable it - LINFO("Disabled shutdown mode"); _shutdown.inShutdown = false; } else { // Else, we have to enable it - LINFO("Shutting down OpenSpace"); _shutdown.timer = _shutdown.waitTime; _shutdown.inShutdown = true; } diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index 077b0a7f5d..fb6c11b4d1 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -412,12 +412,17 @@ void LoadingScreen::render() { using FR = ghoul::fontrendering::FontRenderer; FR& renderer = FR::defaultRenderer(); + + std::string headline = + _hasCatastrophicErrorOccurred ? + "Failure": + "Loading..."; // We use "Loading" to center the text, but render "Loading..." to make it look more // pleasing FR::BoundingBoxInformation bbox = renderer.boundingBox( *_loadingFont, "%s", - "Loading." + headline.substr(0, headline.size() - 2).c_str() ); glm::vec2 loadingLl = glm::vec2( @@ -431,7 +436,7 @@ void LoadingScreen::render() { loadingLl, glm::vec4(1.f, 1.f, 1.f, 1.f), "%s", - "Loading..." + headline.c_str() ); glm::vec2 messageLl; @@ -620,6 +625,10 @@ void LoadingScreen::postMessage(std::string message) { _message = std::move(message); } +void LoadingScreen::setCatastrophicError(CatastrophicError catastrophicError) { + _hasCatastrophicErrorOccurred = catastrophicError; +} + void LoadingScreen::finalize() { _items.erase( std::remove_if(