Open brettle opened 5 months ago
This is not surprising. I'm not sure why you are trying to map this through a SimDevice, but it's not really designed to interact with the low-level timing code like this.
What's important to realize about the simulation callbacks (including the SimDevice ones) is that they are called inline to whatever code made the change (they are not called from a separate thread).
StepTiming() does a lot of work that may be susceptible to deadlocks; in particular it will trigger notifiers as appropriate for the amount of stepped time. We've had a number of hard-to-isolate bugs in this code, so this may be a similar symptom that's simply more reproducible.
Thanks for the quick response! Regarding why we were trying to use a SimDevice
like this, we are working with an external simulator via the ws_server extension and are trying to keep the external simulator's clocks and the robot's clock approximately in sync. Since the wpilib sim framework and the websockets extension already provides a way to communicate state between the robot and the simulator via a SimDevice, this seemed like a natural way to implement that functionality. Fwiw, we have worked around the issue by replacing the call to stepTiming()
with something like:
Notifier pauser = new Notifier(() -> {
SimHooks.pauseTiming();
});
pauser.startSingle(secsBehind);
SimHooks.resumeTiming();
(We actually reuse a single Notifier instead of creating a new one during each callback.)
That doesn't hang, but it doesn't allow the robot code to be run faster than real time and running faster than real time can be useful for some automated testing.
Anyway, perhaps the reproducible test case will be useful in isolating the bugs you mentioned.
Describe the bug
SimHooks.stepTiming()
hangs when called from a callback registered withSimDeviceSim.registerValueChangedCallback()
if anotherSimDeviceSim
has been created.To Reproduce Run the following test (which uses an
ADXRS450_GyroSim
as an example of aSimDeviceSim
):Expected behavior The test should pass (after only 2-3 seconds). Instead, it hangs in the call to
SimHooks.stepTiming()
(until the test times out after 15 secs).Desktop (please complete the following information):
Additional Context The test above uses a
ADXRS450_GyroSim
but the problem also occurs with a newSimDeviceSim
associated with a newSimDevice
.