@@ -164,6 +164,28 @@ private List<CSG> getCachedCSGs(CaDoodleOperation op) {
164164 private void memoryCheck () {
165165 if (getFreeMemory ()>75 ) {
166166 com .neuronrobotics .sdk .common .Log .error ("\n \n Clearing Memory use: " + getFreeMemory () + "\n \n " );
167+ Set <CaDoodleOperation > keySet = cache .keySet ();
168+ int index =0 ;
169+ for (CaDoodleOperation op : keySet ) {
170+ List <CSG > cachedCopy = cache .get (op );
171+ getSaveUpdate ().renderSplashFrame ((int ) (((double ) index ) / ((double ) keySet .size ()) * 100 ),
172+ "Clearing Ram to Disk" );
173+ int opIndex = opToIndex (op );
174+ File cacheFile = new File (objectDir .getAbsolutePath () + delim () + opIndex );
175+ if (!isInitialized ())
176+ if (cacheFile .exists ())
177+ return ;
178+ if (cacheFile .exists ())
179+ cacheFile .delete ();
180+ try (ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream (cacheFile ))) {
181+ oos .writeObject (cachedCopy );
182+ Log .debug ("Saved " + cacheFile .getAbsolutePath ());
183+ } catch (Exception ex ) {
184+ Log .error (ex );
185+ throw new RuntimeException (ex );
186+ }
187+ index ++;
188+ }
167189 cache .clear ();
168190 System .gc ();
169191 }else {
@@ -172,35 +194,6 @@ private void memoryCheck() {
172194 }
173195
174196 private void placeCSGsInCache (CaDoodleOperation op , List <CSG > cachedCopy ) {
175- int opIndex = opToIndex (op );
176- File cacheFile = new File (objectDir .getAbsolutePath ()+delim ()+opIndex );
177-
178- if (cacheFile .exists ())
179- cacheFile .delete ();
180- try (ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream (cacheFile ))) {
181- oos .writeObject (cachedCopy );
182- // ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cacheFile));
183- // List<CSG> readback = (List<CSG>) ois.readObject();
184- // ois.close();
185- // for(int i=0;i<cachedCopy.size();i++) {
186- // CSG down = cachedCopy.get(i);
187- // CSG back = readback.get(i);
188- // if(down.getRegenerate()!= back.getRegenerate()) {
189- // throw new RuntimeException("Data loss! getRegenerate");
190- // }
191- // if(down.getManufacturing()!= back.getManufacturing()) {
192- // throw new RuntimeException("Data loss! getManufacturing");
193- // }
194- // if(down.getParameters(getCsgDBinstance()).size() !=
195- // back.getParameters(getCsgDBinstance()).size()) {
196- // throw new RuntimeException("Data loss! getParameters");
197- // }
198- // }
199- Log .debug ("Saved " +cacheFile .getAbsolutePath ());
200- }catch (Exception ex ) {
201- Log .error (ex );
202- throw new RuntimeException (ex );
203- }
204197 memoryCheck ();
205198 // clear the stale cache value
206199 List <CSG > back = cache .remove (op );
@@ -727,8 +720,13 @@ private void storeResultInCache(CaDoodleOperation op, List<CSG> process) {
727720 throw new RuntimeException ("There can not be 2 objects with the same name after an " + op .getType ()
728721 + " opperation! " + c .getName ());
729722 names .add (c .getName ());
730- cachedCopy .add (cloneCSG (c ).setStorage (new PropertyStorage ()).syncProperties (getCsgDBinstance (),c ).setName (c .getName ())
731- .setRegenerate (c .getRegenerate ()));
723+ CSG cachedVer = cloneCSG (c ).setStorage (new PropertyStorage ()).syncProperties (getCsgDBinstance (),c ).setName (c .getName ())
724+ .setRegenerate (c .getRegenerate ());
725+ if (cachedVer .isHole () != c .isHole ()||
726+ cachedVer .isHide () != c .isHide () ) {
727+ throw new RuntimeException ("Lost properties" );
728+ }
729+ cachedCopy .add (cachedVer );
732730 // cachedCopy.add(c);
733731 }
734732 placeCSGsInCache (op , cachedCopy );
0 commit comments