Browse Source

Bugfix for Concurrent Exception

tags/Release_1
Loch Christian (uib05376) 3 years ago
parent
commit
2b8017c475
3 changed files with 22 additions and 22 deletions
  1. +2
    -8
      app/src/main/java/de/hems/trafficsim/MainActivity.java
  2. +15
    -9
      app/src/main/java/de/hems/trafficsim/TimeRecordView.java
  3. +5
    -5
      app/src/main/java/de/hems/trafficsim/Track.java

+ 2
- 8
app/src/main/java/de/hems/trafficsim/MainActivity.java View File

@@ -45,20 +45,14 @@ public class MainActivity extends AppCompatActivity implements Observer {
if (viewStackRef.getChildCount() > 0)
viewStackRef.removeViewAt(0);
viewStackRef.addView(newTrView);
//viewStackRef.addView(newTrView, 0);
//int childCount = viewStackRef.getChildCount();
//if (childCount > 30) {
// viewStackRef.removeViewAt(childCount-1);
//}
}
});


}

public void onStepButtonClick(View view) {
//for (int j = 0; j < 3000; j++) {
this.track.timeElapse();
//}
this.track.timeElapse();
}

public void onPlayButtonClick(View view) {


+ 15
- 9
app/src/main/java/de/hems/trafficsim/TimeRecordView.java View File

@@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;

import java.util.ConcurrentModificationException;
import java.util.List;

public class TimeRecordView extends View {
@@ -58,16 +59,21 @@ public class TimeRecordView extends View {
int y = 0;
List<List<VehicleTimeRecord>> stepList = this.track.getVtrList();
for (int curStepIdx = stepList.size()-1; curStepIdx >= stepList.size()-1-50 && curStepIdx >= 0; curStepIdx--) {
List<VehicleTimeRecord> step = stepList.get(curStepIdx);
int i = 0;
for (VehicleTimeRecord r : step) {
int left = (int) (this.pixelPerVehicle * r.getPosition());
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1,
y+10, this.paint);
i++;
try {
List<VehicleTimeRecord> step = stepList.get(curStepIdx);
int i = 0;
for (VehicleTimeRecord r : step) {
int left = (int) (this.pixelPerVehicle * r.getPosition());
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1,
y + 10, this.paint);
i++;
}
y += 10;
} catch (ConcurrentModificationException ex) {
System.out.println("Concurrent Exception occured, skipping record");
continue;
}
y += 10;
}
}
}

+ 5
- 5
app/src/main/java/de/hems/trafficsim/Track.java View File

@@ -73,11 +73,11 @@ public class Track extends Observable {
this.setChanged();
this.notifyObservers();
this.clearChanged();
try {
Thread.sleep(125);
} catch (InterruptedException ex) {
}
// try {
// Thread.sleep(125);
// } catch (InterruptedException ex) {
//
// }
}

public float avg_step(int step){


Loading…
Cancel
Save