Fix viewer load termination

Handle streamer success, failure, and cancellation as distinct terminal states so failed or cancelled loads do not finalize as successful models. Clean up partial model/UI state in the full and minimal viewer apps when a load is cancelled or fails.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Dion Moult
2026-04-22 11:27:53 +10:00
parent 29f5132510
commit 4e4553201b
8 changed files with 103 additions and 4 deletions
+33 -2
View File
@@ -95,10 +95,19 @@ void SceneLoader::connectStreamer(GeometryStreamer* streamer) {
this, &SceneLoader::onStreamerInstanceReady, Qt::QueuedConnection);
connect(streamer, &GeometryStreamer::finished,
this, &SceneLoader::onStreamerFinished, Qt::QueuedConnection);
connect(streamer, &GeometryStreamer::cancelled,
this, &SceneLoader::onStreamerCancelled, Qt::QueuedConnection);
connect(streamer, &GeometryStreamer::errorOccurred,
this, &SceneLoader::onStreamerError, Qt::QueuedConnection);
}
void SceneLoader::cancelCurrentLoad() {
if (loading_model_id_ == 0) return;
auto it = models_.find(loading_model_id_);
if (it == models_.end() || it->second.streamer == nullptr) return;
it->second.streamer->cancel();
}
void SceneLoader::startNextLoad() {
if (load_queue_.empty()) {
loading_model_id_ = 0;
@@ -232,6 +241,28 @@ void SceneLoader::onStreamerFinished() {
startNextLoad();
}
void SceneLoader::onStreamerError(const QString& msg) {
emit loadError(loading_model_id_, msg);
void SceneLoader::onStreamerCancelled() {
element_poll_timer_.stop();
const uint32_t mid = loading_model_id_;
loading_model_id_ = 0;
if (mid != 0) {
viewport_->removeModel(mid);
emit loadCancelled(mid);
}
QTimer::singleShot(0, this, &SceneLoader::startNextLoad);
}
void SceneLoader::onStreamerError(const QString& msg) {
element_poll_timer_.stop();
const uint32_t mid = loading_model_id_;
loading_model_id_ = 0;
if (mid != 0) {
viewport_->removeModel(mid);
}
emit loadError(mid, msg);
QTimer::singleShot(0, this, &SceneLoader::startNextLoad);
}