Fixed null pointer exception after changing frameskip
This commit is contained in:
parent
40f030276e
commit
bfd145cff3
@ -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,9 +221,11 @@ 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()));
|
||||
if (this.worker != null) {
|
||||
this.worker.setFrameskip(seekBar.getProgress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
Loading…
Reference in New Issue
Block a user