Skip to content

Commit

Permalink
Fix devices not being released when computer is destroyed while running.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Jan 30, 2022
1 parent ab69c69 commit d6a9360
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/main/java/li/cil/oc2/common/vm/AbstractVirtualMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,7 @@ public void start() {

@Override
public void stop() {
switch (runState) {
case LOADING_DEVICES -> setRunState(VMRunState.STOPPED);
case RUNNING -> stopRunnerAndReset();
}
}

private void joinWorkerThread() {
if (runner != null) {
runner.join();
}
stopRunnerAndReset();
}

public void pauseAndReload() {
Expand All @@ -190,19 +181,6 @@ public void resume(final boolean didDevicesChange) {
state.rpcAdapter.resume(busController, didDevicesChange);
}

protected void stopRunnerAndReset() {
joinWorkerThread();
setRunState(VMRunState.STOPPED);

state.board.setRunning(false);
state.board.reset();
state.rpcAdapter.reset();
state.rpcAdapter.disposeDevices();
state.vmAdapter.disposeDevices();

runner = null;
}

public void tick() {
busController.scan();
setBusState(busController.getState());
Expand Down Expand Up @@ -284,8 +262,27 @@ protected void error(@Nullable final Component message, final boolean reset) {
setBootError(message);
}

protected void stopRunnerAndReset() {
joinWorkerThread();
setRunState(VMRunState.STOPPED);

state.board.setRunning(false);
state.board.reset();
state.rpcAdapter.reset();
state.rpcAdapter.disposeDevices();
state.vmAdapter.disposeDevices();

runner = null;
}

///////////////////////////////////////////////////////////////////

private void joinWorkerThread() {
if (runner != null) {
runner.join();
}
}

private void load() {
if (loadDevicesDelay > 0) {
loadDevicesDelay--;
Expand Down

0 comments on commit d6a9360

Please sign in to comment.