aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2022-01-08 12:55:10 -0600
committeroldmud0 <oldmud0@users.noreply.github.com>2022-01-08 12:55:10 -0600
commitba08ec0379fcbe3c62f1d209bd924de129d0f523 (patch)
tree7a94b361c861e2fb2f257ae4301dd18dc38fdee0
parent3ec3d3a1217842ef72d8326b6803af70b3f3caa9 (diff)
Fix more race conditions in AOLayer loading
- Uninitialized exit_loop variable - Previous load task should stop completely before starting new load task
-rw-r--r--include/aolayer.h2
-rw-r--r--src/aolayer.cpp21
2 files changed, 16 insertions, 7 deletions
diff --git a/include/aolayer.h b/include/aolayer.h
index 4d2629b8..830dd697 100644
--- a/include/aolayer.h
+++ b/include/aolayer.h
@@ -148,7 +148,7 @@ private:
// used in populate_vectors
void load_next_frame();
- std::atomic_bool exit_loop; //awful solution but i'm not fucking using QThread
+ std::atomic_bool exit_loop = false; //awful solution but i'm not fucking using QThread
QFuture<void> frame_loader;
QMutex mutex;
QWaitCondition frameAdded;
diff --git a/src/aolayer.cpp b/src/aolayer.cpp
index 7c899714..a5e1d9bd 100644
--- a/src/aolayer.cpp
+++ b/src/aolayer.cpp
@@ -284,9 +284,11 @@ void AOLayer::start_playback(QString p_image)
this->kill();
return;
}
- QMutexLocker locker(&mutex);
+
if (frame_loader.isRunning())
exit_loop = true; // tell the loader to stop, we have a new image to load
+
+ QMutexLocker locker(&mutex);
this->show();
if (!ao_app->is_continuous_enabled()) {
@@ -561,13 +563,20 @@ void AOLayer::movie_ticker()
}
void AOLayer::populate_vectors() {
- while (!exit_loop && movie_frames.size() < max_frames) {
- load_next_frame();
#ifdef DEBUG_MOVIE
- qDebug() << "[AOLayer::populate_vectors] Loaded frame" << movie_frames.size();
+ qDebug() << "[AOLayer::populate_vectors] Started thread";
#endif
- }
- exit_loop = false;
+ while (!exit_loop && movie_frames.size() < max_frames) {
+ load_next_frame();
+#ifdef DEBUG_MOVIE
+ qDebug() << "[AOLayer::populate_vectors] Loaded frame" << movie_frames.size();
+#endif
+ }
+#ifdef DEBUG_MOVIE
+ if (exit_loop)
+ qDebug() << "[AOLayer::populate_vectors] Exit requested";
+#endif
+ exit_loop = false;
}
void AOLayer::load_next_frame() {