Skip to content

Commit 0946e8f

Browse files
committed
Avoid an infinite loop when stepping forward without next sample.
1 parent e0f16ee commit 0946e8f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/debug/session.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export class Session {
371371
}
372372
}
373373
} else {
374+
let ordersOfMagnitude = 0;
374375
while (true) {
375376
const followingTimePoint = this.timeCursor.offsetByFemtos(this._forwardTimeStep);
376377
const response = await this.connection.queryInterval({
@@ -382,12 +383,15 @@ export class Session {
382383
item_values_encoding: null,
383384
diagnostics: false
384385
});
385-
if (response.samples.length === 1) {
386-
this._forwardTimeStep = this._forwardTimeStep * 2n;
387-
continue;
386+
if (response.samples.length > 1) {
387+
this.timeCursor = TimePoint.fromCXXRTL(response.samples.at(1)!.time);
388+
break;
389+
} else if (ordersOfMagnitude < 30 /* femto -> peta */) {
390+
ordersOfMagnitude += 1;
391+
this._forwardTimeStep = this._forwardTimeStep * 10n;
392+
} else {
393+
throw new RangeError('Could not find a sample to step forward to');
388394
}
389-
this.timeCursor = TimePoint.fromCXXRTL(response.samples.at(1)!.time);
390-
break;
391395
}
392396
}
393397
return this.timeCursor;

0 commit comments

Comments
 (0)