Skip to content

Commit

Permalink
Don't try to get canvas context on null canvas elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl authored and patrickelectric committed Nov 17, 2023
1 parent 4285917 commit aed99b9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/components/widgets/Attitude.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ const angleY = (angle: number): number => {
}
const renderCanvas = (): void => {
if (canvasRef.value === undefined) {
console.error('Canvas ref undefined!')
return
}
if (canvasRef.value === undefined || canvasRef.value === null) return
if (canvasContext.value === undefined) {
console.warn('Canvas context undefined!')
canvasContext.value = canvasRef.value.getContext('2d')
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/Compass.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const smallestDimension = computed(() => (width.value < height.value ? width.val
// Renders the updated canvas state
const renderCanvas = (): void => {
if (canvasRef.value === undefined) return
if (canvasRef.value === undefined || canvasRef.value === null) return
if (canvasContext.value === undefined) canvasContext.value = canvasRef.value.getContext('2d')
const ctx = canvasContext.value
resetCanvas(ctx)
Expand Down
5 changes: 1 addition & 4 deletions src/components/widgets/CompassHUD.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ const angleX = (angle: number): number => {
const canvasRef = ref<HTMLCanvasElement | undefined>()
const canvasContext = ref()
const renderCanvas = (): void => {
if (canvasRef.value === undefined) {
console.error('Canvas ref undefined!')
return
}
if (canvasRef.value === undefined || canvasRef.value === null) return
if (canvasContext.value === undefined) {
console.warn('Canvas context undefined!')
canvasContext.value = canvasRef.value.getContext('2d')
Expand Down
5 changes: 1 addition & 4 deletions src/components/widgets/DepthHUD.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ const distanceY = (altitude: number): number => {
const canvasRef = ref<HTMLCanvasElement | undefined>()
const canvasContext = ref()
const renderCanvas = (): void => {
if (canvasRef.value === undefined) {
console.error('Canvas ref undefined!')
return
}
if (canvasRef.value === undefined || canvasRef.value === null) return
if (canvasContext.value === undefined) {
console.warn('Canvas context undefined!')
canvasContext.value = canvasRef.value.getContext('2d')
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/VirtualHorizon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const smallestDimension = computed(() => (width.value < height.value ? width.val
// Renders the updated canvas state
const renderCanvas = (): void => {
if (canvasRef.value === undefined) return
if (canvasRef.value === undefined || canvasRef.value === null) return
if (canvasContext.value === undefined) canvasContext.value = canvasRef.value.getContext('2d')
const ctx = canvasContext.value
resetCanvas(ctx)
Expand Down

0 comments on commit aed99b9

Please sign in to comment.