ceramic-engine / ceramic

Cross-platform 2D framework written in Haxe that can export natively to desktop (windows, mac, linux), mobile (ios, android), web (js + webgl) and to unity projects
MIT License
263 stars 22 forks source link

clay/runtime/src/Main.hx 314 gets stuck in checkSizeReady in web browsers. #84

Closed qeshi closed 2 years ago

qeshi commented 2 years ago

Hi!

The function checkSizeReady never sets readyToDisplay = true; since appEl.offsetWidth == containerEl.offsetWidth never becomes true when you run your program in a "normal" web browsers.

https://github.com/ceramic-engine/ceramic/blob/4b655f5c902359758b6d410b113436c764c864de/plugins/clay/runtime/src/Main.hx#L314

I tried to change the checkSizeReady function to appEl.offsetWidth <= containerEl.offsetWidth but then you get a layout flicker at the start of your program. (Actually it still gets stuck in a loop on Chrome on my Android phone)

You can see an example of this happening here: https://www.qeshi.com/mori/14/web/

I'm logging the sizes of the elements in this version:

In the beginning of the program the sizes differ.

appEl.offsetWidth: 1280
Main.hx:316 containerEl.offsetWidth: 1920

But if I let the program run, the sizes will become the same. When I console.log the variables by hand when the program finished loading the result is this:

var containerEl = document.getElementById('ceramic-app');
undefined
containerEl
<div id=​"ceramic-app">​<script type=​"text/​javascript" src=​"./​sourceMapSupport.js">​</script>​<script type=​"text/​javascript">​sourceMapSupport.install();​</script>​<script type=​"text/​javascript" src=​"./​mori.js">​</script>​<canvas width=​"1920" height=​"632" id=​"app" __spector_context_type=​"webgl" style=​"width:​ 1920px;​ height:​ 632px;​ background:​ rgb(0, 0, 0)​;​">​</div>​
containerEl.offsetWidth
1920
var appEl = document.getElementById('app');
undefined
appEl
<canvas width=​"1920" height=​"632" id=​"app" __spector_context_type=​"webgl" style=​"width:​ 1920px;​ height:​ 632px;​ background:​ rgb(0, 0, 0)​;​">​
appEl.offsetWidth
1920
appEl.offsetWidth == containerEl.offsetWidth
true

I thought it maybe it had something with in what order the ceramic.App loaders are in. Here: https://github.com/ceramic-engine/ceramic/blob/4b655f5c902359758b6d410b113436c764c864de/runtime/src/ceramic/App.hx#L972

But I not sure anymore because when I trace them there is not that many loaders.

jeremyfa commented 2 years ago

Fixed for a while already