Bugfix for Concurrent Exception

This commit is contained in:
Loch Christian (uib05376) 2020-11-10 21:31:58 +01:00
parent 9c1899fe42
commit 2b8017c475
3 changed files with 22 additions and 22 deletions

View File

@ -45,20 +45,14 @@ public class MainActivity extends AppCompatActivity implements Observer {
if (viewStackRef.getChildCount() > 0) if (viewStackRef.getChildCount() > 0)
viewStackRef.removeViewAt(0); viewStackRef.removeViewAt(0);
viewStackRef.addView(newTrView); viewStackRef.addView(newTrView);
//viewStackRef.addView(newTrView, 0);
//int childCount = viewStackRef.getChildCount();
//if (childCount > 30) {
// viewStackRef.removeViewAt(childCount-1);
//}
} }
}); });
} }
public void onStepButtonClick(View view) { public void onStepButtonClick(View view) {
//for (int j = 0; j < 3000; j++) {
this.track.timeElapse(); this.track.timeElapse();
//}
} }
public void onPlayButtonClick(View view) { public void onPlayButtonClick(View view) {

View File

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

View File

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