Skip to content

Commit 1c0b3e2

Browse files
committed
vcs: fixed test with null Context2D
1 parent 44271fe commit 1c0b3e2

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
node-version: [16.x]
1818
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2121
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v2
22+
uses: actions/setup-node@v3
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
cache: 'npm'

src/common/baseplatform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
887887
if (!this.isRunning() && isRaster(this.machine) && this.machine.getRasterCanvasPosition) {
888888
const {x,y} = this.machine.getRasterCanvasPosition();
889889
if (x >= 0 || y >= 0) {
890-
const ctx = this.video.getContext();
890+
const ctx = this.video?.getContext();
891891
if (ctx) {
892892
drawCrosshair(ctx, x, y, 1);
893893
}

src/common/emu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export class VectorVideo extends RasterVideo {
216216
}
217217

218218
export function drawCrosshair(ctx:CanvasRenderingContext2D, x:number, y:number, width:number) {
219+
if (!ctx?.setLineDash) return; // for unit testing
219220
ctx.fillStyle = 'rgba(0,0,0,0.25)';
220221
ctx.fillRect(x-2, 0, 5, 32767);
221222
ctx.fillRect(0, y-2, 32767, 5);

src/platform/vcs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ class VCSPlatform extends BasePlatform {
438438
updateVideoDebugger() {
439439
const {x,y} = this.getRasterCanvasPosition();
440440
if (x >= 0 || y >= 0) {
441-
const ctx = this.canvas.getContext('2d');
442-
drawCrosshair(ctx, x, y, 2);
441+
const ctx = this.canvas?.getContext('2d');
442+
if (ctx) {
443+
drawCrosshair(ctx, x, y, 2);
444+
}
443445
}
444446
}
445447
};

0 commit comments

Comments
 (0)