Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ca4c052

Browse files
committed
Fix crash if a Context is stopped immediately after creation
1 parent 2978d8e commit ca4c052

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/java/com/team766/framework/Context.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ private void transferControl(final ControlOwner thisOwner, final ControlOwner de
335335
* This is the entry point for this Context's worker thread.
336336
*/
337337
private void threadFunction() {
338-
// OS threads run independently of one another, so we need to wait until
339-
// the baton is passed to us before we can start running the user's code
340-
waitForControl(ControlOwner.SUBROUTINE);
341338
try {
339+
// OS threads run independently of one another, so we need to wait until
340+
// the baton is passed to us before we can start running the user's code
341+
waitForControl(ControlOwner.SUBROUTINE);
342342
// Call into the user's code.
343343
m_func.run(this);
344344
Logger.get(Category.FRAMEWORK)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.team766.framework;
2+
3+
import com.team766.TestCase;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class ContextTest extends TestCase {
7+
/// Regression test: calling stop() on a Context before it is allowed to
8+
/// run the first time should not crash the program.
9+
@Test
10+
public void testStopOnFirstTick() {
11+
var lc = Scheduler.getInstance().startAsync(Procedure.NO_OP);
12+
lc.stop();
13+
14+
step();
15+
16+
assertTrue(lc.isDone());
17+
}
18+
}

0 commit comments

Comments
 (0)