diff --git a/wpilibc/src/main/native/cpp/Preferences.cpp b/wpilibc/src/main/native/cpp/Preferences.cpp index 0c82f545cb..e17db69b70 100644 --- a/wpilibc/src/main/native/cpp/Preferences.cpp +++ b/wpilibc/src/main/native/cpp/Preferences.cpp @@ -30,6 +30,14 @@ static Instance& GetInstance() { return instance; } +#ifndef __FRC_ROBORIO__ +namespace frc::impl { +void ResetPreferencesInstance() { + GetInstance() = Instance(); +} +} // namespace frc::impl +#endif + Preferences* Preferences::GetInstance() { ::GetInstance(); static Preferences instance; diff --git a/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp b/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp index f8be7de441..ac1c8ad4f5 100644 --- a/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp +++ b/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp @@ -48,11 +48,23 @@ struct Instance { }; } // namespace -static Instance& GetInstance() { - static Instance instance; +static std::unique_ptr& GetInstanceHolder() { + static std::unique_ptr instance = std::make_unique(); return instance; } +static Instance& GetInstance() { + return *GetInstanceHolder(); +} + +#ifndef __FRC_ROBORIO__ +namespace frc::impl { +void ResetLiveWindow() { + std::make_unique().swap(GetInstanceHolder()); +} +} // namespace frc::impl +#endif + std::shared_ptr Instance::GetOrAdd(wpi::Sendable* sendable) { auto data = std::static_pointer_cast( wpi::SendableRegistry::GetData(sendable, dataHandle)); diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp index 13b6e1db42..508839440e 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp @@ -29,11 +29,23 @@ struct Instance { }; } // namespace -static Instance& GetInstance() { - static Instance instance; +static std::unique_ptr& GetInstanceHolder() { + static std::unique_ptr instance = std::make_unique(); return instance; } +static Instance& GetInstance() { + return *GetInstanceHolder(); +} + +#ifndef __FRC_ROBORIO__ +namespace frc::impl { +void ResetSmartDashboardInstance() { + std::make_unique().swap(GetInstanceHolder()); +} +} // namespace frc::impl +#endif + void SmartDashboard::init() { GetInstance(); } diff --git a/wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp b/wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp index 3ad39e54e0..2c591e9fcd 100644 --- a/wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp +++ b/wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp @@ -60,11 +60,24 @@ Component& SendableRegistryInst::GetOrAdd(void* sendable, return *components[compUid - 1]; } -static SendableRegistryInst& GetInstance() { - static SendableRegistryInst instance; +static std::unique_ptr& GetInstanceHolder() { + static std::unique_ptr instance = + std::make_unique(); return instance; } +static SendableRegistryInst& GetInstance() { + return *GetInstanceHolder(); +} + +#ifndef __FRC_ROBORIO__ +namespace wpi::impl { +void ResetSendableRegistry() { + std::make_unique().swap(GetInstanceHolder()); +} +} // namespace wpi::impl +#endif + void SendableRegistry::SetLiveWindowBuilderFactory( std::function()> factory) { GetInstance().liveWindowFactory = std::move(factory);