From 2886c0ad9059ad72c897a2c4c66b0c99771e6b39 Mon Sep 17 00:00:00 2001 From: f0e <7321764+f0e@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:28:28 +1000 Subject: [PATCH] fix: crash when callback is uninitialised --- src/cli/main.cpp | 2 -- src/common/rendering.cpp | 6 +++--- src/common/rendering.h | 7 ++++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index e614bc9..52d63d1 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -19,8 +19,6 @@ int main(int argc, char* argv[]) { try { CLI11_PARSE(app, argc, argv); - printf("Hi\n"); - cli::run(inputs, outputs, configPaths, preview, verbose); return 0; diff --git a/src/common/rendering.cpp b/src/common/rendering.cpp index 27d8b74..eba98d7 100644 --- a/src/common/rendering.cpp +++ b/src/common/rendering.cpp @@ -7,7 +7,7 @@ void c_rendering::render_videos() { if (!queue.empty()) { current_render = queue.front(); - rendering.progress_callback(); + run_callbacks(); try { current_render->render(); @@ -19,7 +19,7 @@ void c_rendering::render_videos() { // finished rendering, delete queue.erase(queue.begin()); current_render = nullptr; - rendering.progress_callback(); + run_callbacks(); renders_queued = !queue.empty(); } @@ -287,7 +287,7 @@ bool c_render::do_render(s_render_commands render_commands) { status.start_time = std::chrono::high_resolution_clock::now(); } - rendering.progress_callback(); + rendering.run_callbacks(); } line.clear(); diff --git a/src/common/rendering.h b/src/common/rendering.h index daf5ffb..58c37a7 100644 --- a/src/common/rendering.h +++ b/src/common/rendering.h @@ -77,7 +77,7 @@ class c_rendering { public: std::vector> queue; std::shared_ptr current_render; - std::function progress_callback; + std::optional> progress_callback; bool renders_queued; public: @@ -86,6 +86,11 @@ class c_rendering { void queue_render(std::shared_ptr render); void stop_rendering(); + + void run_callbacks() { + if (progress_callback) + (*progress_callback)(); + } }; inline c_rendering rendering;