Corrupted j3o file

While saving a scene in the terrain editor, I got the following Heap Space error, and it looks like it also corrupted the j3o file so it can’t be loaded or opened anymore.

java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:3236)
	at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
	at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
	at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
	at java.io.OutputStream.write(OutputStream.java:75)
	at com.jme3.export.binary.BinaryExporter.save(BinaryExporter.java:287)
	at com.jme3.gde.core.assets.AssetDataObject.saveAsset(AssetDataObject.java:234)
	at com.jme3.gde.core.assets.SpatialAssetDataObject.saveAsset(SpatialAssetDataObject.java:111)
	at com.jme3.gde.core.assets.AssetData.saveAsset(AssetData.java:140)
	at com.jme3.gde.core.scene.SceneApplication.checkSave(SceneApplication.java:509)
	at com.jme3.gde.core.scene.SceneApplication.access$1400(SceneApplication.java:91)
	at com.jme3.gde.core.scene.SceneApplication$5.run(SceneApplication.java:459)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Thankfully I was editing scenes with both the SDK and JMB today, though - I was able to immediately recover the file since I had a non-corrupted version opened in JMB from a few minutes prior to the error.

I forgot that I haven’t upped the heap space setting in the SDK config file since I upgraded versions, so that should solve the problem from happening again anytime soon.

But in the case that I make this mistake and have a file become corrupted again, is there any way to fix / restore a corrupted j3o scene aside from frequently backing up my assets?

How does JMB handle this type of potential problem?

I believe JMB also corrupts the file if a heap space error occurs while saving, although it only ever happened to me once. Last week I had a file get corrupted the same way in JMB after I had been using the editor for a long time and had a lot of scenes open. But I think I was also playing around with the new model spawner tool and set a larger radius and brush power than I should have set while using the batch mode .

So it seems like a problem that occurs anytime an OutOfMemory error occurs in the middle of saving a file.

Wonder if its possible to write it to a temp folder first and then move at end of write process?

That sounds like it would solve the problem, if possible.

But I guess I also don’t know very much about how the current write process works for the j3o save to say whether or not that would be as easy of a solution as it sounds.

Unfortunately, until someone submits a patch to write to a temp file and rename back when done, the only solution would be to pull the last version back from source control or backups.

Sometimes that 20 minutes or an hour worth of changes can be pretty significant, though.

I try to save a scene to a temp file before updating “opened” file.