Skip to content

Commit 7cf753f

Browse files
committed
delay loading of stored models to avoid exception (for nested models)
remove console msgs
1 parent f1acfde commit 7cf753f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/com/lushprojects/circuitjs1/client/CirSim.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ public void init() {
202202
ui.setColors(positiveColor, negativeColor, neutralColor, selectColor, currentColor);
203203
ui.setWheelSensitivity();
204204

205+
CustomCompositeModel.loadModelsFromStorage();
206+
205207
loader = new CircuitLoader(this, sim, scopeManager, menus);
206208

207209
if (startCircuitText != null) {

src/com/lushprojects/circuitjs1/client/CustomCompositeModel.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ static void initModelMap() {
6666
globalModelMap.put(d.name, d);
6767
sequenceNumber = 1;
6868

69+
loadInternalModels();
70+
}
71+
72+
public static void loadModelsFromStorage() {
6973
// get models from local storage
7074
Storage stor = Storage.getLocalStorageIfSupported();
7175
if (stor != null) {
@@ -97,21 +101,18 @@ static void initModelMap() {
97101
}
98102
}
99103
}
100-
101-
loadInternalModels();
102104
}
103105

104106
static CustomCompositeModel getModelWithName(String name) {
105107
if (globalModelMap == null)
106108
initModelMap();
107109
CustomCompositeModel lm = localModelMap.get(name);
108110
if (lm != null) {
109-
CirSim.console("getModelWithName: " + name + " found in local");
111+
//CirSim.console("getModelWithName: " + name + " found in local");
110112
return lm;
111113
}
112114
lm = globalModelMap.get(name);
113-
if (lm != null)
114-
CirSim.console("getModelWithName: " + name + " found in global");
115+
//if (lm != null) CirSim.console("getModelWithName: " + name + " found in global");
115116
return lm;
116117
}
117118

@@ -179,20 +180,20 @@ static CustomCompositeModel undumpModel(StringTokenizer st) {
179180
String name = CustomLogicModel.unescape(st.nextToken());
180181
CustomCompositeModel model = getModelWithName(name);
181182
if (model == null) {
182-
CirSim.console("undumpModel: creating new local model " + name);
183+
//CirSim.console("undumpModel: creating new local model " + name);
183184
model = new CustomCompositeModel();
184185
model.name = name;
185186
localModelMap.put(name, model);
186187
sequenceNumber++;
187188
} else if (globalModelMap.containsKey(name) && !localModelMap.containsKey(name)) {
188189
// model exists in global map; create a local shadow instead of modifying global
189-
CirSim.console("undumpModel: creating local shadow for global model " + name);
190+
//CirSim.console("undumpModel: creating local shadow for global model " + name);
190191
model = new CustomCompositeModel();
191192
model.name = name;
192193
localModelMap.put(name, model);
193194
sequenceNumber++;
194195
} else {
195-
CirSim.console("undumpModel: updating existing local model " + name);
196+
//CirSim.console("undumpModel: updating existing local model " + name);
196197
}
197198
model.undump(st);
198199
return model;
@@ -359,20 +360,20 @@ static CustomCompositeModel undumpModelXml(XMLDeserializer xml) {
359360
String name = xml.parseStringAttr("nm", null);
360361
CustomCompositeModel model = getModelWithName(name);
361362
if (model == null) {
362-
CirSim.console("undumpModelXml: creating new local model " + name);
363+
//CirSim.console("undumpModelXml: creating new local model " + name);
363364
model = new CustomCompositeModel();
364365
model.name = name;
365366
localModelMap.put(name, model);
366367
sequenceNumber++;
367368
} else if (globalModelMap.containsKey(name) && !localModelMap.containsKey(name)) {
368369
// model exists in global map; create a local shadow instead of modifying global
369-
CirSim.console("undumpModelXml: creating local shadow for global model " + name);
370+
//CirSim.console("undumpModelXml: creating local shadow for global model " + name);
370371
model = new CustomCompositeModel();
371372
model.name = name;
372373
localModelMap.put(name, model);
373374
sequenceNumber++;
374375
} else {
375-
CirSim.console("undumpModelXml: updating existing local model " + name);
376+
//CirSim.console("undumpModelXml: updating existing local model " + name);
376377
}
377378
model.undumpXml(xml);
378379
return model;
@@ -468,7 +469,7 @@ static void replaceModel(CustomCompositeModel model) {
468469
}
469470

470471
static void clearLocalModels() {
471-
CirSim.console("clearLocalModels: clearing " + localModelMap.size() + " local models");
472+
//CirSim.console("clearLocalModels: clearing " + localModelMap.size() + " local models");
472473
localModelMap.clear();
473474
sequenceNumber++;
474475
}

0 commit comments

Comments
 (0)