Fixed null pointer exception after changing frameskip

This commit is contained in:
Loch Christian (uib05376) 2020-11-14 23:28:51 +01:00 committed by Chris
parent 40f030276e
commit bfd145cff3

View File

@ -175,15 +175,25 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
float newMaxVelocity = ((SeekBar) findViewById(R.id.maxVelocitySeekBar)).getProgress();
SeekBar brakeProbabilitySeekBar = (SeekBar) findViewById(R.id.brakeProbabilitySeekBar);
float newBrakeProb = (float)brakeProbabilitySeekBar.getProgress() / (float)brakeProbabilitySeekBar.getMax();
float newBrakeProb = (float)brakeProbabilitySeekBar.getProgress()
/ (float)brakeProbabilitySeekBar.getMax();
int newDelay = ((SeekBar)(findViewById(R.id.simDelaySeekBar))).getProgress();
int newFrameskip = ((SeekBar)(findViewById(R.id.frameskipSeekBar))).getProgress();
this.track = new Track(newNoOfVehicles, newTrackLength, newBrakeProb, newMaxVelocity, newDelay, defaultHistoryLength);
boolean wasRunning = this.worker != null;
if (wasRunning) {
this.worker.setStop(true);
try {
this.worker.join();
} catch (InterruptedException ex) { }
}
this.track = new Track(newNoOfVehicles, newTrackLength, newBrakeProb, newMaxVelocity,
newDelay, defaultHistoryLength);
this.renderer.setTrack(this.track);
if (this.worker != null) { // There was a simulation running already
this.stopWorker();
if (wasRunning) {
this.worker = new Worker(track, this, renderer, newFrameskip);
this.worker.start();
}
@ -211,7 +221,9 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
} else if (seekBar == (SeekBar)(findViewById(R.id.frameskipSeekBar))) {
TextView tv = (TextView)(findViewById(R.id.frameSkipTextView));
tv.setText(String.valueOf(seekBar.getProgress()));
this.worker.setFrameskip(seekBar.getProgress());
if (this.worker != null) {
this.worker.setFrameskip(seekBar.getProgress());
}
}
}