mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-01-30 12:32:43 +00:00
Fix crash on exit if a process is currently running
This commit is contained in:
parent
9955890023
commit
32ca9d41de
@ -594,6 +594,11 @@ main(int argc, char *argv[]) {
|
||||
BOOST_LOG(error) << "Platform failed to initialize"sv;
|
||||
}
|
||||
|
||||
auto proc_deinit_guard = proc::init();
|
||||
if (!proc_deinit_guard) {
|
||||
BOOST_LOG(error) << "Proc failed to initialize"sv;
|
||||
}
|
||||
|
||||
reed_solomon_init();
|
||||
auto input_deinit_guard = input::init();
|
||||
if (video::probe_encoders()) {
|
||||
|
@ -40,6 +40,22 @@ namespace proc {
|
||||
|
||||
proc_t proc;
|
||||
|
||||
class deinit_t: public platf::deinit_t {
|
||||
public:
|
||||
~deinit_t() {
|
||||
proc.terminate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes proc functions
|
||||
* @return Unique pointer to `deinit_t` to manage cleanup
|
||||
*/
|
||||
std::unique_ptr<platf::deinit_t>
|
||||
init() {
|
||||
return std::make_unique<deinit_t>();
|
||||
}
|
||||
|
||||
void
|
||||
process_end(bp::child &proc, bp::group &proc_handle) {
|
||||
if (!proc.running()) {
|
||||
@ -266,7 +282,12 @@ namespace proc {
|
||||
}
|
||||
|
||||
proc_t::~proc_t() {
|
||||
terminate();
|
||||
// It's not safe to call terminate() here because our proc_t is a static variable
|
||||
// that may be destroyed after the Boost loggers have been destroyed. Instead,
|
||||
// we return a deinit_t to main() to handle termination when we're exiting.
|
||||
// Once we reach this point here, termination must have already happened.
|
||||
assert(!placebo);
|
||||
assert(!_process.running());
|
||||
}
|
||||
|
||||
std::string_view::iterator
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <boost/process.hpp>
|
||||
|
||||
#include "config.h"
|
||||
#include "platform/common.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace proc {
|
||||
@ -116,5 +117,8 @@ namespace proc {
|
||||
std::optional<proc::proc_t>
|
||||
parse(const std::string &file_name);
|
||||
|
||||
std::unique_ptr<platf::deinit_t>
|
||||
init();
|
||||
|
||||
extern proc_t proc;
|
||||
} // namespace proc
|
||||
|
Loading…
x
Reference in New Issue
Block a user