From 8e9fcffa65348212015a7e19467ced87f9645d92 Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Sat, 5 Nov 2022 01:13:45 -0400 Subject: [PATCH] Fix seg fault in CharonClient due to out of order initialization. --- Specter/src/Specter/Editor/SourceDialog.cpp | 3 --- Specter/src/Specter/ImGui/ImGuiLayer.cpp | 2 +- Specter/src/Specter/Physics/DataSource.cpp | 17 ++++++++--------- Specter/src/Specter/Physics/PhysicsLayer.cpp | 1 - .../Specter/Physics/nscldaq/CharonClient.cpp | 1 - .../src/Specter/Physics/nscldaq/CharonClient.h | 2 +- .../Physics/nscldaq/CharonOnlineSource.cpp | 1 - 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Specter/src/Specter/Editor/SourceDialog.cpp b/Specter/src/Specter/Editor/SourceDialog.cpp index d3970dc..7f5a4d1 100644 --- a/Specter/src/Specter/Editor/SourceDialog.cpp +++ b/Specter/src/Specter/Editor/SourceDialog.cpp @@ -120,11 +120,8 @@ namespace Specter { if (ImGui::Button("Ok")) { - SPEC_INFO("Here"); PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, m_bitflags); - SPEC_INFO("Here"); Application::Get().OnEvent(event); - SPEC_INFO("Here"); ImGui::CloseCurrentPopup(); } diff --git a/Specter/src/Specter/ImGui/ImGuiLayer.cpp b/Specter/src/Specter/ImGui/ImGuiLayer.cpp index 1e51845..b551a02 100644 --- a/Specter/src/Specter/ImGui/ImGuiLayer.cpp +++ b/Specter/src/Specter/ImGui/ImGuiLayer.cpp @@ -126,7 +126,7 @@ namespace Specter { void ImGuiLayer::OnImGuiRender() { //Demo's used to figure out how to do things. - //Should not be on for actual NavProject for + //Should not be on for actual SpecProject for //real use //static bool show = true; //ImGui::ShowDemoWindow(&show); diff --git a/Specter/src/Specter/Physics/DataSource.cpp b/Specter/src/Specter/Physics/DataSource.cpp index 914c878..ff7b698 100644 --- a/Specter/src/Specter/Physics/DataSource.cpp +++ b/Specter/src/Specter/Physics/DataSource.cpp @@ -18,15 +18,14 @@ namespace Specter { //loc=either an ip address or a file location, port=address port, or unused in case of file DataSource* CreateDataSource(const std::string& location, const std::string& port, uint16_t header, DataSource::SourceType type, uint64_t coincidenceWindow) { - SPEC_INFO("Here in create with type: {0} loc:{1} port:{2} ", ConvertDataSourceTypeToString(type), location, port); switch(type) { - case DataSource::SourceType::CompassOffline : SPEC_INFO("CompassOff"); return new CompassRun(location, coincidenceWindow); - case DataSource::SourceType::CompassOnline : SPEC_INFO("CompassOn"); return new CompassOnlineSource(location, port, header, coincidenceWindow); - case DataSource::SourceType::DaqromancyOffline: SPEC_INFO("DaqOff"); return new DYFileSource(location, coincidenceWindow); - case DataSource::SourceType::DaqromancyOnline: SPEC_INFO("DaqOn"); return new DYOnlineSource(location, port, coincidenceWindow); - case DataSource::SourceType::CharonOnline: SPEC_INFO("CharOn"); return new CharonOnlineSource(location, port); - case DataSource::SourceType::None: SPEC_INFO("None"); return nullptr; + case DataSource::SourceType::CompassOffline: return new CompassRun(location, coincidenceWindow); + case DataSource::SourceType::CompassOnline: return new CompassOnlineSource(location, port, header, coincidenceWindow); + case DataSource::SourceType::DaqromancyOffline: return new DYFileSource(location, coincidenceWindow); + case DataSource::SourceType::DaqromancyOnline: return new DYOnlineSource(location, port, coincidenceWindow); + case DataSource::SourceType::CharonOnline: return new CharonOnlineSource(location, port); + case DataSource::SourceType::None: return nullptr; } SPEC_WARN("Invalid DataSourceType at CreateDataSource!"); return nullptr; @@ -37,8 +36,8 @@ namespace Specter { switch(type) { case DataSource::SourceType::None: return "None"; - case DataSource::SourceType::CompassOnline : return "CompassOnline"; - case DataSource::SourceType::CompassOffline : return "CompassOffline"; + case DataSource::SourceType::CompassOnline: return "CompassOnline"; + case DataSource::SourceType::CompassOffline: return "CompassOffline"; case DataSource::SourceType::DaqromancyOffline: return "DaqromancyOffline"; case DataSource::SourceType::DaqromancyOnline: return "DaqromancyOnline"; case DataSource::SourceType::CharonOnline: return "CharonOnline"; diff --git a/Specter/src/Specter/Physics/PhysicsLayer.cpp b/Specter/src/Specter/Physics/PhysicsLayer.cpp index 4c5f677..8b59903 100644 --- a/Specter/src/Specter/Physics/PhysicsLayer.cpp +++ b/Specter/src/Specter/Physics/PhysicsLayer.cpp @@ -109,7 +109,6 @@ namespace Specter { SPEC_PROFILE_FUNCTION(); std::scoped_lock guard(m_sourceMutex); //Shouldn't matter for this, but safety first m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetBitFlags(), event.GetSourceType(), event.GetCoincidenceWindow())); - SPEC_INFO("Here"); if (m_source->IsValid()) { SPEC_INFO("Attach successful. Enabling data pull..."); diff --git a/Specter/src/Specter/Physics/nscldaq/CharonClient.cpp b/Specter/src/Specter/Physics/nscldaq/CharonClient.cpp index 02978c7..b75efd6 100644 --- a/Specter/src/Specter/Physics/nscldaq/CharonClient.cpp +++ b/Specter/src/Specter/Physics/nscldaq/CharonClient.cpp @@ -5,7 +5,6 @@ namespace Specter { CharonClient::CharonClient(const std::string& hostname, const std::string& port) : m_socket(m_context) { - SPEC_INFO("here"); Connect(hostname, port); } diff --git a/Specter/src/Specter/Physics/nscldaq/CharonClient.h b/Specter/src/Specter/Physics/nscldaq/CharonClient.h index a5a19de..cc1b3ca 100644 --- a/Specter/src/Specter/Physics/nscldaq/CharonClient.h +++ b/Specter/src/Specter/Physics/nscldaq/CharonClient.h @@ -30,8 +30,8 @@ namespace Specter { void ReadHeader(); void ReadBody(); - asio::ip::tcp::socket m_socket; asio::io_context m_context; + asio::ip::tcp::socket m_socket; std::thread m_ioThread; StygianMessage m_tempMessage; diff --git a/Specter/src/Specter/Physics/nscldaq/CharonOnlineSource.cpp b/Specter/src/Specter/Physics/nscldaq/CharonOnlineSource.cpp index e62e03e..5d63070 100644 --- a/Specter/src/Specter/Physics/nscldaq/CharonOnlineSource.cpp +++ b/Specter/src/Specter/Physics/nscldaq/CharonOnlineSource.cpp @@ -7,7 +7,6 @@ namespace Specter { CharonOnlineSource::CharonOnlineSource(const std::string& hostname, const std::string& port) : DataSource(0), m_client(hostname, port) { - SPEC_INFO("Here"); m_validFlag = m_client.IsConnected(); m_readyEvents.emplace_back();