Skip to content

Commit

Permalink
Force SendableRegistry initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Oct 21, 2024
1 parent 2c9ad83 commit f3a323f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wpilibc/src/main/native/cpp/Alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@

#include <fmt/format.h>
#include <networktables/NTSendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>

#include "frc/Errors.h"
#include "frc/smartdashboard/SmartDashboard.h"

using namespace frc;

Alert::SendableAlerts& Alert::GetGroupSendable(std::string_view group) {
// Force initialization of SendableRegistry before our magic static to prevent
// incorrect destruction order.
wpi::SendableRegistry::EnsureInitialized();
static wpi::StringMap<Alert::SendableAlerts> groups;

auto [iter, exists] = groups.try_emplace(group);
Expand Down
4 changes: 4 additions & 0 deletions wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ void ResetSendableRegistry() {
} // namespace wpi::impl
#endif

void SendableRegistry::EnsureInitialized() {
GetInstance();
}

void SendableRegistry::SetLiveWindowBuilderFactory(
std::function<std::unique_ptr<SendableBuilder>()> factory) {
GetInstance().liveWindowFactory = std::move(factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class SendableRegistry final {

using UID = size_t;

/**
* Initializes the SendableRegistry. This is used to ensure initialization and
* destruction order relative to Sendables.
*/
static void EnsureInitialized();

/**
* Sets the factory for LiveWindow builders.
*
Expand Down

0 comments on commit f3a323f

Please sign in to comment.