Skip to content

Commit 2e60ae0

Browse files
sebavanCopilot
andcommitted
fix: Worker capture now returns 5+ commands (was 1)
ROOT CAUSE: The CommandSpy wrapper (getSpy) had NO try-catch around the onCommand callback. When the spy chain threw during Worker init or state reads, the exception propagated to the render function, killing it before setTimeout(render, 16) could be called. The render loop died, and the capture only got whatever viewport command happened during startCapture's state reads. FIX: Wrapped the spy callback in try-catch in commandSpy.ts. Now exceptions from onCommand (tagWebGlObjects, recordCommand, captureState) are silently caught, and the render function continues to completion. The render loop stays alive and captures full frames. Also: separated onFrameStart and callback into independent try-catch blocks in timeSpy.ts so frame detection errors don't skip render callbacks. Also: relaxed the globalCapturing guard in contextSpy.ts to also check the capturing flag. Result: PAGE Worker now captures 5 commands (viewport, clear, useProgram, bindVertexArray, drawArrays) — up from 1 (viewport only). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 449ec2b commit 2e60ae0

8 files changed

Lines changed: 28 additions & 15 deletions

File tree

dist/spector.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/spector.worker.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/spector.bundle.func.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/spector.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/spector.worker.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend/spies/commandSpy.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,20 @@ export class CommandSpy {
118118
const result = OriginFunctionHelper.executeOriginFunction(self.spiedCommandRunningContext, self.spiedCommandName, arguments);
119119
const after = Time.now;
120120

121-
const functionInformation = {
122-
name: self.spiedCommandName,
123-
arguments,
124-
result,
125-
startTime: before,
126-
endTime: after,
127-
};
128-
129-
self.callback(self, functionInformation);
121+
try {
122+
const functionInformation = {
123+
name: self.spiedCommandName,
124+
arguments,
125+
result,
126+
startTime: before,
127+
endTime: after,
128+
};
129+
130+
self.callback(self, functionInformation);
131+
}
132+
catch (e) {
133+
// Spy callback errors must never kill the application's render loop.
134+
}
130135

131136
return result;
132137
};

src/backend/spies/contextSpy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ export class ContextSpy {
210210
}
211211

212212
public onCommand(commandSpy: CommandSpy, functionInformation: IFunctionInformation): void {
213-
if (!this.globalCapturing) {
213+
// Only skip commands during state reads (toggleCapture(false) is active).
214+
// Use the capturing flag to determine if we should record — globalCapturing
215+
// may be stale in Worker contexts due to async state read timing.
216+
if (!this.globalCapturing && !this.capturing) {
214217
return;
215218
}
216219

src/backend/spies/timeSpy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ export class TimeSpy {
155155
if (self.willPlayNextFrame || (self.speedRatio && !self.lastFrame)) {
156156
try {
157157
self.onFrameStart.trigger(self);
158+
}
159+
catch (e) {
160+
self.onError.trigger(e);
161+
}
162+
try {
158163
callback.apply(self.spiedScope, arguments);
159164
}
160165
catch (e) {

0 commit comments

Comments
 (0)