Skip to content

Commit

Permalink
try to prevent segmentation fault in osc_server when unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed May 14, 2024
1 parent 78cf250 commit 3918637
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions libtascar/include/osc_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* License (GPL)
*
* Copyright (C) 2018 Giso Grimm
* Copyright (C) 2024 Giso Grimm
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -315,9 +316,9 @@ namespace TASCAR {
std::string osc_srv_url;
std::string prefix;
lo_server_thread lost;
bool initialized;
bool isactive;
bool verbose;
std::atomic_bool initialized = false;
std::atomic_bool isactive = false;
bool verbose = false;
std::map<std::string, data_element_t> datamap;
std::atomic<bool> runscriptthread;
std::atomic<bool> cancelscript;
Expand Down
7 changes: 4 additions & 3 deletions libtascar/src/osc_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ int string2proto(const std::string& proto)
osc_server_t::osc_server_t(const std::string& multicast,
const std::string& port, const std::string& proto,
bool verbose_)
: osc_srv_addr(multicast), osc_srv_port(port), initialized(false),
isactive(false), verbose(verbose_)
: osc_srv_addr(multicast), osc_srv_port(port), verbose(verbose_)
{
runscriptthread = true;
cancelscript = false;
Expand Down Expand Up @@ -625,6 +624,8 @@ osc_server_t::osc_server_t(const std::string& multicast,

int osc_server_t::dispatch_data(void* data, size_t size)
{
if(!isactive)
return 0;
// std::lock_guard<std::mutex> lk{mtxdispatch};
lo_server srv(lo_server_thread_get_server(lost));
return lo_server_dispatch_data(srv, data, size);
Expand Down Expand Up @@ -890,8 +891,8 @@ void osc_server_t::activate()
void osc_server_t::deactivate()
{
if(initialized) {
lo_server_thread_stop(lost);
isactive = false;
lo_server_thread_stop(lost);
if(verbose)
std::cerr << "server inactive\n";
}
Expand Down
5 changes: 4 additions & 1 deletion libtascar/src/session_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ const std::string& showstring(const std::string& s)

TASCAR::tsc_reader_t::~tsc_reader_t()
{
chdir(orig_path.c_str());
auto result = chdir(orig_path.c_str());
if(result != 0)
TASCAR::add_warning("Unable to change to directory \"" + orig_path + "\"." +
strerror(errno));
}

TASCAR::tsc_reader_t::tsc_reader_t(const std::string& filename_or_data,
Expand Down
7 changes: 4 additions & 3 deletions plugins/src/tascarmod_oscserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ oscserver_t::oscserver_t(const TASCAR::module_cfg_t& cfg)
: module_base_t(cfg), srv_addr(""), srv_port("9877"), srv_proto("TCP"),
srv(NULL)
{
GET_ATTRIBUTE_(srv_addr);
GET_ATTRIBUTE_(srv_port);
GET_ATTRIBUTE_(srv_proto);
GET_ATTRIBUTE(srv_addr, "",
"Server address (network device, multicast address)");
GET_ATTRIBUTE(srv_port, "", "Port number");
GET_ATTRIBUTE(srv_proto, "", "Server protocol (UDP or TCP)");
srv = new TASCAR::osc_server_t(srv_addr, srv_port, srv_proto);
srv->add_method("", NULL, osc_recv_, this);
srv->activate();
Expand Down

0 comments on commit 3918637

Please sign in to comment.