MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ set_and_transfer_context()

MAYAFLUX_API void MayaFlux::set_and_transfer_context ( Core::Engine  instance)

Replaces the default engine with a new instance.

Parameters
instanceNew engine instance to use as default

Transfers state from the old engine to the new one if possible.

Warning
This function uses move semantics. After calling this function, the engine instance passed as parameter will be left in a moved-from state and should not be used further. This is intentional to avoid resource duplication and ensure proper transfer of ownership. Users should be careful to not access the moved-from instance after calling this function.

This function is intended for advanced use cases where custom engine configuration is required beyond what the standard initialization functions provide.

Definition at line 61 of file Core.cpp.

62{
63 bool is_same_instance = false;
64
65 {
66 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
67 is_same_instance = (&instance == internal::engine_ref.get());
68 if (internal::engine_ref && !is_same_instance && internal::engine_ref->is_running()) {
69 internal::engine_ref->Pause();
70 }
71 }
72
73 if (internal::engine_ref && !is_same_instance) {
74 internal::engine_ref->End();
75 }
76
77 if (!is_same_instance) {
78 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
79 internal::engine_ref = std::make_unique<Core::Engine>(std::move(instance));
80 internal::initialized = true;
81 }
82}

References MayaFlux::internal::engine_mutex, MayaFlux::internal::engine_ref, and MayaFlux::internal::initialized.