Wait for initialization when adding assets at runtime. Correctly destroy the RenderableGalaxy shader when deinitializing (closes #1601)

This commit is contained in:
Alexander Bock
2022-02-22 23:24:37 +01:00
parent 73f6938619
commit 78fd5b78da
4 changed files with 18 additions and 0 deletions

View File

@@ -56,6 +56,8 @@ public:
void enqueue(std::function<void()> f);
void clearTasks();
bool hasOutstandingTasks() const;
private:
friend class Worker;

View File

@@ -494,6 +494,11 @@ void RenderableGalaxy::deinitializeGL() {
_raycaster = nullptr;
}
global::renderEngine->removeRenderProgram(_pointsProgram.get());
_pointsProgram = nullptr;
global::renderEngine->removeRenderProgram(_billboardsProgram.get());
_billboardsProgram = nullptr;
glDeleteVertexArrays(1, &_pointsVao);
glDeleteBuffers(1, &_positionVbo);
glDeleteBuffers(1, &_colorVbo);

View File

@@ -100,6 +100,13 @@ void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) {
}
std::vector<SceneGraphNode*> MultiThreadedSceneInitializer::takeInitializedNodes() {
// Some of the scene graph nodes might still be in the initialization queue and we
// should wait for those to finish or we end up in some half-initialized state since
// other parts of the application already know about their existence
while (_threadPool.hasOutstandingTasks()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
std::lock_guard g(_mutex);
std::vector<SceneGraphNode*> nodes = std::move(_initializedNodes);
return nodes;

View File

@@ -99,4 +99,8 @@ void ThreadPool::clearTasks() {
} // release lock
}
bool ThreadPool::hasOutstandingTasks() const {
return !tasks.empty();
}
} // namespace openspace