Skip to content

Commit

Permalink
stop the graph in a thread
Browse files Browse the repository at this point in the history
  • Loading branch information
j20001970 committed May 14, 2022
1 parent 1ec580f commit 0e0175a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions GDMP/framework/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <map>
#include <string>
#include <thread>

#include "Array.hpp"
#include "File.hpp"
Expand Down Expand Up @@ -142,20 +143,24 @@ void Graph::add_packet(String stream_name, Ref<Packet> packet) {
}

void Graph::stop() {
absl::Status result = [this]() -> absl::Status {
if (!graph) {
// Has to stop the graph in a thread to prevent break rendering.
std::thread([this]() -> void {
absl::Status result = [this]() -> absl::Status {
if (!graph) {
return absl::OkStatus();
}
if (started) {
MP_RETURN_IF_ERROR(graph->CloseAllPacketSources());
MP_RETURN_IF_ERROR(graph->WaitUntilDone());
graph.reset(nullptr);
}
started = false;
return absl::OkStatus();
}();
if (!result.ok()) {
Godot::print(result.message().data());
}
if (started) {
MP_RETURN_IF_ERROR(graph->CloseAllPacketSources());
MP_RETURN_IF_ERROR(graph->WaitUntilIdle());
}
started = false;
return absl::OkStatus();
}();
if (!result.ok()) {
Godot::print(result.message().data());
}
}).join();
}

#if !MEDIAPIPE_DISABLE_GPU
Expand Down

0 comments on commit 0e0175a

Please sign in to comment.