Bug or not bug? Cannot read property 'clientX' of undefined: firstTouch.clientX in library_sdl.js

848 views
Skip to first unread message

Pavel Duvanov

unread,
May 22, 2017, 11:55:14 AM5/22/17
to emscripten-discuss
Hi, all!

I ran into a problem under mobile browsers, which occurs in the code library_sdl.js:

      switch(event.type) {
       
case 'touchstart': case 'touchmove': {
         
event.preventDefault();


         
var touches = [];
         
         
// Clear out any touchstart events that we've already processed
         
if (event.type === 'touchstart') {
           
for (var i = 0; i < event.touches.length; i++) {
             
var touch = event.touches[i];
             
if (SDL.downFingers[touch.identifier] != true) {
                SDL
.downFingers[touch.identifier] = true;
                touches
.push(touch);
             
}
           
}
         
} else {
            touches
= event.touches;
         
}
         
         
var firstTouch = touches[0];
         
if (event.type == 'touchstart') {
            SDL
.DOMButtons[0] = 1;
         
}
         
var mouseEventType;
         
switch(event.type) {
           
case 'touchstart': mouseEventType = 'mousedown'; break;
           
case 'touchmove': mouseEventType = 'mousemove'; break;
         
}
         
var mouseEvent = {
            type
: mouseEventType,
            button
: 0,
            pageX
: firstTouch.clientX,
            pageY
: firstTouch.clientY
         
};

Question: why is there no verification that the touches array is not empty? I mean this case:

 var firstTouch = touches[0];

Is there bug or not?

Thanks!

--
Pavel Duvanov

Jukka Jylänki

unread,
May 30, 2017, 4:29:14 AM5/30/17
to emscripte...@googlegroups.com
Agreed this looks like a bug. Does this kind of fix work? https://github.com/kripken/emscripten/pull/5258

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages