HaxePunk / HaxePunk

Cross-platform desktop, mobile, and WebGL game engine, based on FlashPunk
MIT License
489 stars 126 forks source link

Error in touches iterator in Input.update in js #356

Closed robo-corg closed 9 years ago

robo-corg commented 9 years ago

Getting "TypeError: undefined is not an object (evaluating 'touch.update')" in the js console on my iphone.

This seems to be the following line of haxepunk code: https://github.com/HaxePunk/HaxePunk/blob/dev/com/haxepunk/utils/Input.hx#L436

It looks like touches has one touch in it and hasNext() returns true however calling next() returns undefined. This seems like a haxe javascript target error but I thought filing this here first would make more sense since I have no idea what I am doing :)

Haxe version 3.1.3 openfl: 2.2.4 haxepunk: 2.5.3

Found this while testing on my iphone with ios version 8.1.2

robo-corg commented 9 years ago

Clearing the cache on the phone and deleting my bin directory seems to have mysteriously fixed things.

scriptorum commented 9 years ago

That is strange, but not the weirdest thing I've seen that was fixed by removing intermediate files. If this problem comes back with Input.hx and you can reproduce it with a clean build, please reopen this ticket.

robo-corg commented 9 years ago

I think I have found a way to semi-reliably reproduce this and it seems to hinge on --debug:

Works:

Clean and build with debugging (fab deploys to my server):

lime clean html5 && lime build html5 -debug && fab deploy_html5

Manually close safari on iphone. Clear browser cache. Reopen safari to game

Breaks:

Clean and build without debugging:

lime clean html5 && lime build html5  && fab deploy_html5

Manually close safari on iphone. Clear browser cache. Reopen safari to game

robo-corg commented 9 years ago

It actually looks like it maybe a timing issue with how the page loads since repeated manual closing of safari with clearing the browser caches seems to trigger the bug at random. It seems the load order once its cached is deterministic however and touch will cause a js error until you clear the cache and get lucky again.

scriptorum commented 9 years ago

Ugh, hasNext() returning true and next() returning undefined is concerning; that makes it seem like an issue in Haxe's IntMap. It's possible the touches map has a null Touch value, although I don't see yet how that would happen without thread-safety coming to play. Instead of iterating on values, can you iterate on keys and see what's in there? Something like:

for(k in Input.touches.keys())
    trace("Key:" + k + " = " + Input.touches.get(k));

Does this issue come up if you run the debug version locally? Does the issue come up on any other browsers (on iOS, e.g. Dolphin, Chrome).

robo-corg commented 9 years ago

I think it is just nulls or undefined (despite it saying there are more values on the iterator). Given that it happens randomly I think there is something broken with the way lime embeds and starts itself up in html5. I haven't been able to dig in much more than that. My theory is event handlers are triggering before the entire application is ready (specifically ones related to asset preloading).