Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewPort> vps = app.getRenderManager().getPostViews();
List<ViewPort> 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<ViewPort> 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte[]>(numIcons);
for (int i = 0; i < numIcons; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading