Skip to content

Commit

Permalink
Merge pull request #176 from Tresjs/feature/add-0px-height-canvas-par…
Browse files Browse the repository at this point in the history
…ent-warning

feat: adding warning when  canvas parent height is 0px
  • Loading branch information
alvarosabu committed Mar 28, 2023
2 parents 8b2bbb3 + 6a5f0c1 commit 5460d55
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/composables/useRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ export function useRenderer(canvas: MaybeElementRef, container: MaybeElementRef,
const { setState } = useTres()

const { width, height } = resolveUnref(windowSize) ? useWindowSize() : useElementSize(container)
const { logError } = useLogger()
const { logError, logWarning } = useLogger()
const { pixelRatio } = useDevicePixelRatio()
const { pause, resume } = useRenderLoop()
const aspectRatio = computed(() => width.value / height.value)

if (!resolveUnref(windowSize) && container?.value?.offsetHeight === 0) {
logWarning(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
You could set windowSize=true to force the canvas to be the size of the window.`)
}

const updateRendererSize = () => {
if (!renderer.value) {
return
Expand Down

0 comments on commit 5460d55

Please sign in to comment.