diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/VideoRecorderAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/VideoRecorderAppState.java index 88ff87526..1dc41e8fa 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/VideoRecorderAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/VideoRecorderAppState.java @@ -171,34 +171,90 @@ public void setQuality(float quality) { @Override public void initialize(AppStateManager stateManager, Application app) { super.initialize(stateManager, app); - this.app = app; - this.oldTimer = app.getTimer(); - app.setTimer(new IsoTimer(framerate)); + + // Validate the input application instance + if (app == null) { + throw new IllegalArgumentException("Application instance cannot be null"); + } + + // Defensive copying: store only what is needed + this.oldTimer = app.getTimer(); // Keep the old timer + app.setTimer(new IsoTimer(framerate)); // Set the custom timer for this state + + RenderManager renderManager = app.getRenderManager(); + if (renderManager == null) { + throw new IllegalStateException("RenderManager is not initialized in the Application"); + } + + // Determine the file to write video to if none is specified if (file == null) { String filename = System.getProperty("user.home") + File.separator + "jMonkey-" + System.currentTimeMillis() / 1000 + ".avi"; file = new File(filename); } + processor = new VideoProcessor(); - List vps = app.getRenderManager().getPostViews(); + List viewPorts = renderManager.getPostViews(); - for (int i = vps.size() - 1; i >= 0; i-- ) { - lastViewPort = vps.get(i); + // Safely select the last enabled ViewPort + for (int i = viewPorts.size() - 1; i >= 0; i--) { + lastViewPort = viewPorts.get(i); if (lastViewPort.isEnabled()) { break; } } - lastViewPort.addProcessor(processor); + + // Attach the processor to the selected ViewPort + if (lastViewPort != null) { + lastViewPort.addProcessor(processor); + } else { + throw new IllegalStateException("No enabled ViewPort found to attach the VideoProcessor"); + } } +// public void initialize(AppStateManager stateManager, Application app) { +// super.initialize(stateManager, app); +// this.app = app; +// this.oldTimer = app.getTimer(); +// app.setTimer(new IsoTimer(framerate)); +// if (file == null) { +// String filename = System.getProperty("user.home") + File.separator + "jMonkey-" + System.currentTimeMillis() / 1000 + ".avi"; +// file = new File(filename); +// } +// processor = new VideoProcessor(); +// List vps = app.getRenderManager().getPostViews(); +// +// for (int i = vps.size() - 1; i >= 0; i-- ) { +// lastViewPort = vps.get(i); +// if (lastViewPort.isEnabled()) { +// break; +// } +// } +// lastViewPort.addProcessor(processor); +// } @Override public void cleanup() { - lastViewPort.removeProcessor(processor); - app.setTimer(oldTimer); + if (lastViewPort != null) { + lastViewPort.removeProcessor(processor); + } + + // Restore the old timer + if (app != null) { + app.setTimer(oldTimer); + } + initialized = false; file = null; shutdownExecutor(); + super.cleanup(); } +// public void cleanup() { +// lastViewPort.removeProcessor(processor); +// app.setTimer(oldTimer); +// initialized = false; +// file = null; +// super.cleanup(); +// } private class WorkItem { diff --git a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java index 9c8af90e9..f28f40ab2 100644 --- a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java @@ -45,6 +45,8 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.ArrayList; import javax.imageio.ImageIO; @@ -167,7 +169,9 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { if (leIn.readInt() == 0x6e6f6369) { // we have 'icon' // We have an icon and from this point on // the rest is only icons. - int icoLength = leIn.readInt(); + byte[] icoLengthBytes = new byte[4]; + leIn.readFully(icoLengthBytes); + int icoLength = ByteBuffer.wrap(icoLengthBytes).order(ByteOrder.LITTLE_ENDIAN).getInt(); ciDat.numImages = numIcons; icons = new ArrayList(numIcons); for (int i = 0; i < numIcons; i++) { diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index 4525acbd7..a06fb01a2 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -36,6 +36,7 @@ import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.Path; import java.nio.file.StandardCopyOption; diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/objects/FbxImage.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/objects/FbxImage.java index 7ef329933..37d637764 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/objects/FbxImage.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/objects/FbxImage.java @@ -111,7 +111,9 @@ private Image createImage() { Texture tex = null; try { tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content)); - } catch(Exception e) {} + } catch(Exception e) { + throw new RuntimeException("Failed to load texture: " + filename, e); + } if(tex != null) image = tex.getImage(); }