Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy interactive on mobile lead to Uncaught TypeError on other sprite events. #4228

Closed
YannCaron opened this issue Dec 13, 2018 · 5 comments

Comments

@YannCaron
Copy link

YannCaron commented Dec 13, 2018

Version

  • Phaser Version: 3.15.1

  • Operating system: android

  • Browser: chrome

Description

On mobile device, when a draggable interactive image is destroyed, the 'pointerdown' event on other 'draggable' sprite lead to 'Uncaught Type Error' exception.

Here is the example to illustrate:

const sprite1 = this.add.image(150, 150, 'Character Pink Girl');
sprite1.setInteractive({
    pixelPerfect: true,
    draggable: true,
});
sprite1.on('pointerdown', () => {
    sprite1.destroy();
});

const sprite2 = this.add.image(250, 150, 'Character Pink Girl');
sprite2.setInteractive({
    pixelPerfect: true,
    draggable: true,
});
sprite2.on('pointerdown', () => {
    sprite2.destroy();
});

image

On Desktop, everything is fine. We can click on both images and both are deleted properly.
On my Android phone, the first one works well but the second one does not works.
It generate the following LogCat log:

12-13 16:28:51.817 14773 14773 I chromium: [INFO:CONSOLE(76876)] "Uncaught TypeError: Cannot read property 'dragState' of undefined", source: http://192.168.42.238:4000/vendors~game.js (76876)

After some investigation, it appears that problem come from the fact to destroy the image into the event.
When doing this:

const sprite1 = this.add.image(150, 150, 'Character Pink Girl');
sprite1.destroy();

const sprite2 = this.add.image(250, 150, 'Character Pink Girl');
sprite2.setInteractive({
    pixelPerfect: true,
    draggable: true,
});
sprite2.on('pointerdown', () => {
    sprite2.destroy();
});

it works well.

Thanks

Big thank to Phaser team 👍

@YannCaron
Copy link
Author

YannCaron commented Dec 13, 2018

I found source of the problem.
We must destroy the event first:

const sprite1 = this.add.image(150, 150, 'Character Pink Girl');
sprite1.setInteractive({
    pixelPerfect: true,
    draggable: true,
});
const handler = () => {
    sprite1.off('pointerdown', handler); // here !
    sprite1.destroy();
};
sprite1.on('pointerdown', handler);

I don't know if it is even a bug or my misunderstanding :-)

@Loick1109
Copy link

Loick1109 commented Apr 15, 2019

i get the same error when i destroy my image inside of the dragenter event

          this.input.on('dragenter',  (pointer:PointerEvent, gameObject, dropZone)=> {

            
            try {
              this.myBillet = gameObject as Billet;
                
              let v:string = gameObject.texture.key;
              v=v.substr(0,v.length-2);
             
              
              if(this.myBillet._zone!="ZONE_REPONSE" && dropZone.name=="ZONE_REPONSE"){
               
                this.myBillet._zone=dropZone.name;
                this.billets_sur_table.push(this.myBillet);
                if(!this.tables.containsKey(v)){
    
                 
                  this.tables.add(dropZone.name,this.billets_sur_table);
                    
                 }
                 else{
                  this.tables[this.myBillet._zone]=this.billets_sur_table;
                 }
                 var billet = new Billet(this,gameObject.input.dragStartX, gameObject.input.dragStartY,v,this.groupe_portefeuilles,"ZONE_CREATION", {font:"20px 'Arial'",fill:"#000"});
                 this.tweens.add({
                  targets: gameObject,
                  y: pointer.y,
                  x:pointer.x,
                  duration: 1000,
                  ease: 'Power2',
                  completeDelay: 1000
              });
              }else if(this.myBillet._zone=="ZONE_REPONSE" && dropZone.name=="ZONE_CREATION"){
            
                var b = this.myBillet;
                var evens = _.remove(this.billets_sur_table, function(n) {
                  return n == b;
                });
                
                this.tables["ZONE_REPONSE"]=this.billets_sur_table;
                this.myBillet.input.enabled=false;
                this.myBillet.destroy();
               
             
              }

how can i fixe that

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

@YannCaron
Copy link
Author

Many thanks @photonstorm. I Put to test it as an entry in my backlog. Therefor it will be done soon :-)

@YannCaron
Copy link
Author

I've just tested on v3.16.2 and it works perfectly. Many thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants