Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,57 @@ public void initialize(RenderManager rm, ViewPort viewPort) {

@Override
public void reshape(ViewPort vp, int w, int h) {
if (this.width == w && this.height == h) {
return;
}

this.width = w;
this.height = h;

// Wait for all work items to finish processing with timeout
if (freeItems != null) {
try {
long startTime = System.currentTimeMillis();
long timeout = 5000; // 5 second timeout
while (freeItems.size() < numCpus) {
if (System.currentTimeMillis() - startTime > timeout) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.WARNING,
"Timeout waiting for work items to complete during reshape. Some frames may be lost.");
break;
}
Thread.sleep(10);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot you are blocking the main loop here, this is not going to work... if you really need to wait , mark your intention with a boolean flag and then in the update look for whatever condition you want to wait for

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 1e0bb05. Now using a flag-based approach: reshape() sets reshapePending flag, and preFrame() handles the actual resize when all work items are available (non-blocking check).

}
} catch (InterruptedException ex) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
}
}

// Close the current writer and generate new filename for resized video
if (writer != null) {
try {
writer.finishAVI();
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.INFO,
"Window resized from {0}x{1} to {2}x{3}. Previous recording saved to: {4}",
new Object[]{writer.width, writer.height, w, h, file.getAbsolutePath()});
} catch (Exception ex) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, "Error closing video on reshape", ex);
}
writer = null;

// Generate a new filename for the resized video
String originalPath = file.getAbsolutePath();
int dotIndex = originalPath.lastIndexOf('.');
String basePath = dotIndex > 0 ? originalPath.substring(0, dotIndex) : originalPath;
String extension = dotIndex > 0 ? originalPath.substring(dotIndex) : ".avi";
file = new File(basePath + "-" + (System.currentTimeMillis() / 1000) + extension);
}

// Recreate work items with new dimensions
freeItems.clear();
usedItems.clear();
for (int i = 0; i < numCpus; i++) {
freeItems.add(new WorkItem(w, h));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,57 @@ public void initialize(RenderManager rm, ViewPort viewPort) {

@Override
public void reshape(ViewPort vp, int w, int h) {
if (this.width == w && this.height == h) {
return;
}

this.width = w;
this.height = h;

// Wait for all work items to finish processing with timeout
if (freeItems != null) {
try {
long startTime = System.currentTimeMillis();
long timeout = 5000; // 5 second timeout
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot same as the other appstate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 1e0bb05. Applied the same non-blocking flag-based approach to the desktop version.

while (freeItems.size() < numCpus) {
if (System.currentTimeMillis() - startTime > timeout) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.WARNING,
"Timeout waiting for work items to complete during reshape. Some frames may be lost.");
break;
}
Thread.sleep(10);
}
} catch (InterruptedException ex) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
}
}

// Close the current writer and generate new filename for resized video
if (writer != null) {
try {
writer.finishAVI();
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.INFO,
"Window resized from {0}x{1} to {2}x{3}. Previous recording saved to: {4}",
new Object[]{writer.width, writer.height, w, h, file.getAbsolutePath()});
} catch (Exception ex) {
Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, "Error closing video on reshape", ex);
}
writer = null;

// Generate a new filename for the resized video
String originalPath = file.getAbsolutePath();
int dotIndex = originalPath.lastIndexOf('.');
String basePath = dotIndex > 0 ? originalPath.substring(0, dotIndex) : originalPath;
String extension = dotIndex > 0 ? originalPath.substring(dotIndex) : ".avi";
file = new File(basePath + "-" + (System.currentTimeMillis() / 1000) + extension);
}

// Recreate work items with new dimensions
freeItems.clear();
usedItems.clear();
for (int i = 0; i < numCpus; i++) {
freeItems.add(new WorkItem(w, h));
}
}

@Override
Expand Down