Skip to content

Commit

Permalink
fix: transferControlToOffscreen cannot set properties of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr.Mao committed Nov 8, 2024
1 parent f4605c1 commit dc8f447
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 11 additions & 5 deletions packages/vue3-pixi/src/components/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ export const Application = defineComponent({
const pixiApp = ref()

let app: App<Container> | undefined

function mount() {

let view: HTMLCanvasElement | OffscreenCanvas | undefined = canvas.value
if (props.transferControlToOffscreen)
canvas.value?.transferControlToOffscreen()
view = canvas.value?.transferControlToOffscreen() as OffscreenCanvas

const context = canvas.value?.getContext('webgl', {
const context = view?.getContext('webgl', {
alpha: props.alpha,
antialias: props.antialias,
depth: props.depth,
Expand All @@ -64,7 +63,14 @@ export const Application = defineComponent({
if (!context)
warn('could not crate webgl context')

const inst = new _Application({ view: canvas.value, ...props })
const params = { ...props } as { [key: string]: any }
// delete params.autoDensity

const inst = new _Application({ view, ...params })

inst.view.width = params.width
inst.view.height = params.height

pixiApp.value = markRaw(inst)

app = createApp({
Expand Down
4 changes: 3 additions & 1 deletion packages/vue3-pixi/src/composables/useScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Application, ICanvas } from 'pixi.js'
import { Rectangle } from 'pixi.js'

import { computedWithControl, useResizeObserver } from '@vueuse/core'

import { useApplication } from './useApplication'

export function useScreen(app?: Ref<Application<ICanvas>>): Ref<Rectangle> {
Expand All @@ -17,7 +18,8 @@ export function useScreen(app?: Ref<Application<ICanvas>>): Ref<Rectangle> {
() => useApp.value?.screen || defaultRectangle,
)

useResizeObserver(view, screen.trigger)
if (view?.value instanceof HTMLCanvasElement)
useResizeObserver(view, screen.trigger)

return screen
}
Expand Down

0 comments on commit dc8f447

Please sign in to comment.