Don't call preRun when stop is pressed during init phase - #39
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes CommandOpMode’s lifecycle so preRun() (and therefore run()) is only entered when the OpMode actually transitions into the active/running state (i.e., the Start button was pressed), avoiding an unintended preRun() call when Stop is pressed during init.
Changes:
- Guarded the
preRun()+ run-loop block withopModeIsActive()so it only executes after Start. - Preserved existing init-loop behavior and ensured
end()/reset()still run via the existingfinallyblock.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ah, that makes sense. However, why does the while loop need to be in the if loop? if (opModeIsActive()) {
preRun();
while (opModeIsActive()) {
run();
}
}should be the same as: if (opModeIsActive()) {
preRun();
}
while (opModeIsActive()) {
run();
} |
|
Yes, both are equivalent. I just picked the first pattern because it's what the FTC SDK uses in the samples. |
|
Ah, I see - that makes sense, I will merge this in. Do note that |
Pull Requests
Small fix for #34 to only call
preRun()if the start button was pressed. When stop is pressed during init, neitherpreRun()norrun()should be called.What kind of change does this PR introduce?
Did this PR introduce a breaking change?