mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Check for invalid handle in destructors (#7212)
Moved-from objects have invalid handles.
This commit is contained in:
@@ -84,10 +84,12 @@ Counter::Counter(EncodingType encodingType,
|
||||
}
|
||||
|
||||
Counter::~Counter() {
|
||||
try {
|
||||
SetUpdateWhenEmpty(true);
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
if (m_counter != HAL_kInvalidHandle) {
|
||||
try {
|
||||
SetUpdateWhenEmpty(true);
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,13 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
}
|
||||
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
// Disable the PWM in case it was running.
|
||||
try {
|
||||
DisablePWM();
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
if (m_handle != HAL_kInvalidHandle) {
|
||||
// Disable the PWM in case it was running.
|
||||
try {
|
||||
DisablePWM();
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,11 @@ PWM::PWM(int channel, bool registerSendable) {
|
||||
}
|
||||
|
||||
PWM::~PWM() {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
FRC_ReportError(status, "Channel {}", m_channel);
|
||||
if (m_handle != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
FRC_ReportError(status, "Channel {}", m_channel);
|
||||
}
|
||||
}
|
||||
|
||||
void PWM::SetPulseTime(units::microsecond_t time) {
|
||||
|
||||
@@ -61,8 +61,12 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
|
||||
Relay::~Relay() {
|
||||
int32_t status = 0;
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
}
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::Set(Relay::Value value) {
|
||||
|
||||
@@ -90,10 +90,11 @@ TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) {
|
||||
}
|
||||
|
||||
TimedRobot::~TimedRobot() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_StopNotifier(m_notifier, &status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
if (m_notifier != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_StopNotifier(m_notifier, &status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
}
|
||||
}
|
||||
|
||||
void TimedRobot::AddPeriodic(std::function<void()> callback,
|
||||
|
||||
Reference in New Issue
Block a user