From 0b09084b9239e4741b0c466d355d5c0646776e8a Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Wed, 14 Aug 2013 12:54:30 +0200 Subject: [PATCH] minor bugfix: simulation speed was not restored correctly --- tools/cooja/java/se/sics/cooja/Simulation.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 71c5bfc86..0286c8da6 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -659,7 +659,10 @@ public class Simulation extends Observable implements Runnable { availableMoteTypes, moteTypeClassName ); - if (newClass != null && !newClass.equals(moteTypeClassName)) { + if (newClass == null) { + throw new MoteType.MoteTypeCreationException("No mote type class selected"); + } + if (!newClass.equals(moteTypeClassName)) { logger.warn("Changing mote type class: " + moteTypeClassName + " -> " + newClass); moteTypeClassName = newClass; } @@ -989,7 +992,7 @@ public class Simulation extends Observable implements Runnable { * @param newSpeedLimit */ public void setSpeedLimit(final Double newSpeedLimit) { - invokeSimulationThread(new Runnable() { + Runnable r = new Runnable() { public void run() { if (newSpeedLimit == null) { speedLimitNone = true; @@ -1008,7 +1011,14 @@ public class Simulation extends Observable implements Runnable { Simulation.this.setChanged(); Simulation.this.notifyObservers(this); } - }); + }; + if (!isRunning()) { + /* Simulation is stopped, change speed immediately */ + r.run(); + } else { + /* Change speed from simulation thread */ + invokeSimulationThread(r); + } } /**