mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Fix LiveWindow attempting to start listeners on uninitialized sendables (#1463)
Additionally adds a defensive check in SendableBuilderImpl to avoid the NPE.
This commit is contained in:
committed by
Peter Johnson
parent
3d546428ab
commit
97ba195b88
@@ -175,6 +175,10 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
if (m_impl->liveWindowEnabled == enabled) return;
|
||||
Scheduler* scheduler = Scheduler::GetInstance();
|
||||
m_impl->startLiveWindow = enabled;
|
||||
m_impl->liveWindowEnabled = enabled;
|
||||
// Force table generation now to make sure everything is defined
|
||||
UpdateValuesUnsafe();
|
||||
if (enabled) {
|
||||
scheduler->SetEnabled(false);
|
||||
scheduler->RemoveAll();
|
||||
@@ -184,13 +188,15 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
}
|
||||
scheduler->SetEnabled(true);
|
||||
}
|
||||
m_impl->startLiveWindow = enabled;
|
||||
m_impl->liveWindowEnabled = enabled;
|
||||
m_impl->enabledEntry.SetBoolean(enabled);
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValues() {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
UpdateValuesUnsafe();
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValuesUnsafe() {
|
||||
// Only do this if either LiveWindow mode or telemetry is enabled.
|
||||
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) return;
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ void SendableBuilderImpl::UpdateTable() {
|
||||
|
||||
void SendableBuilderImpl::StartListeners() {
|
||||
for (auto& property : m_properties) property.StartListener();
|
||||
m_controllableEntry.SetBoolean(true);
|
||||
if (m_controllableEntry) m_controllableEntry.SetBoolean(true);
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StopListeners() {
|
||||
for (auto& property : m_properties) property.StopListener();
|
||||
m_controllableEntry.SetBoolean(false);
|
||||
if (m_controllableEntry) m_controllableEntry.SetBoolean(false);
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StartLiveWindowMode() {
|
||||
|
||||
@@ -208,6 +208,11 @@ class LiveWindow {
|
||||
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
|
||||
/**
|
||||
* Updates the entries, without using a mutex or lock.
|
||||
*/
|
||||
void UpdateValuesUnsafe();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -65,6 +65,9 @@ public class LiveWindow {
|
||||
*/
|
||||
public static synchronized void setEnabled(boolean enabled) {
|
||||
if (liveWindowEnabled != enabled) {
|
||||
startLiveWindow = enabled;
|
||||
liveWindowEnabled = enabled;
|
||||
updateValues(); // Force table generation now to make sure everything is defined
|
||||
Scheduler scheduler = Scheduler.getInstance();
|
||||
if (enabled) {
|
||||
System.out.println("Starting live window mode.");
|
||||
@@ -77,8 +80,6 @@ public class LiveWindow {
|
||||
}
|
||||
scheduler.enable();
|
||||
}
|
||||
startLiveWindow = enabled;
|
||||
liveWindowEnabled = enabled;
|
||||
enabledEntry.setBoolean(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,9 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
for (Property property : m_properties) {
|
||||
property.startListener();
|
||||
}
|
||||
m_controllableEntry.setBoolean(true);
|
||||
if (m_controllableEntry != null) {
|
||||
m_controllableEntry.setBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +119,9 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
for (Property property : m_properties) {
|
||||
property.stopListener();
|
||||
}
|
||||
m_controllableEntry.setBoolean(false);
|
||||
if (m_controllableEntry != null) {
|
||||
m_controllableEntry.setBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user