# (Bug?) Touches Array sometimes doesn't remove objects if touch has ended

**URL:** <https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892>\
**Category:** Processing for Android\
**Created:** [November 26, 2022, 11:50pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892 "2022-11-26T23:50:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [November 26, 2022, 11:50pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/1 "2022-11-26T23:50:22Z")

</div>

With this code example:

```auto
void setup() {
  fullScreen();
}

void draw() {
  background(0);
  fill(255);
  for (TouchEvent.Pointer p : touches) {
    circle(p.x, p.y, 400);
  }
}

```

If I touch with one finger, a circle is displayed (at it’s position)  
If I touch with a second finger, a second circle is displayed  
If I pull up the second finger without changing the position of the first one, the second circle still is being displayed  
Only if I move or let go of the first finger, the second circle also disappeares.

Interestingly, the `touchEnded()` function is still correctly executed when letting go of the second finger.

It’s easiest to test this by holding one finger steadily and then tapping with a second.

Tested on the following devices:

```plaintext
moto g5 (LineageOS 19.1 / Android 11) : Bug occured
Xiaomi 12 Lite (Android 12) : Bug occured
Samsung Galaxy A5 2016 (Android 7) : Bug occured
Honor 9X Lite (Android 9) : Bug DIDN'T occur

```

Video Links:  
[Xiaomi 12 Lite (Android 12)](https://youtu.be/le-x3YV3oC4)  
[Galaxy A5 2016 (Android 7)](https://youtube.com/shorts/RdFjVRcQMLE)  
[Motorola moto g5 (LineageOS 19.1 / Android 11)](https://youtu.be/JfKYAoTXpKY)  
I don’t have a Video of the Honor 9X Lite unfortunately

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 27, 2022, 6:54am UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/2 "2022-11-27T06:54:44Z")

</div>

Hi @JoLi,

Interesting…

I’ve now tested it 5mins on my S22(Android 13) and have to say that I can’t reproduce it. 🤔  
I’ve also looked at the processing code and the `touches` gets updated directly before triggering the `touchStarted` / `touchEnded` events, which means that both should have the same issue you described above…  
Maybe you can check if the framerate drops or draw is called at all…

```auto
void setup() {
  fullScreen();
  textSize(50);
}

void draw() {
  background(0);
  fill(255);
  String msg = String.format("f: %d, t:",int(frameRate));
  for (TouchEvent.Pointer p : touches) {
    msg += " " + p.id;
    circle(p.x, p.y, 400);
  }
  text(msg ,50,50);
}

```

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [November 27, 2022, 2:18pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/3 "2022-11-27T14:18:32Z")

</div>

![ezgif-3-02bdfae67b](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/e/5e67baee04f45ff84c9ea0c5097109f7b7dee5d3.webp)  
doesn’t seem like it drops the fps significantly…  
I don’t really get what you mean by “or draw is called at all”, because obviously stuff is being displayed, so draw has to be called, or am I wrong?

This should show grey at the beginning,  
then red if the last action was `touchStarted()`  
and green if the last one was `touchEnded()`

```auto
color c;

void setup() {
  fullScreen();
  textSize(76);
  textAlign(CENTER);
  fill(255);
  c = color(100);
}

void draw() {
  background(c);
  for (TouchEvent.Pointer p : touches) {
    text(p.id, width*0.5, height*0.5+p.id*76);
    push();
    fill(255);
    circle(p.x, p.y, 400);
    pop();
  }
}

void touchStarted() {
  c = color(100, 0, 0);
}

void touchEnded() {
  c = color(0, 100, 0);
}

```

[Link to video of that code running on my Xiaomi 12 Lite](https://youtu.be/v3VK_b6zldk)  
(Unfortunately I couldn’t convert this video to webp and post it directly here, sorry for the inconvenience…)

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 27, 2022, 2:56pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/4 "2022-11-27T14:56:58Z")

</div>

Hi @JoLi,

> [@JoLi](#):
>
> what you mean by “or draw is called at all”,

Meant maybe graphics is persistent by the devices graphicbuffer. Would be still displayed but without getting updates from draw.  
But as far as I spot it correct in your vid the frameRate text is flickering 59/60. So it definitely gets updated …  
Nevertheless, I tried it once more to reproduce it on my mobile (+ on my old S9 Android 10) but still no luck. All fine on my device. 🤷

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [November 27, 2022, 3:41pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/5 "2022-11-27T15:41:18Z")

</div>

I just “achieved” this by tapping shortly with 4 Fingers?  
Console doesn’t show any Errors, and the last Event apparently was `touchStarted()` as the background is red.  
I can easily reproduce this about every fourth attempt.  
This screen stays until I tap (or hold) again.

 ![IMG_20221127_163629](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/5/759ac16d42b5e5f5e44d2d6410316348b5c147cc.jpeg)  
also works when using your code example that shows the fps and touches at the top, and the fps doesn’t drop and continues to flicker between 59 and 60. `t:` shows `0 1 2 3` as it does in my code, too.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 27, 2022, 5:07pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/6 "2022-11-27T17:07:05Z")

</div>

That’s on my mobile…  
 ![ezgif.com-gif-maker](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/0/a02f3eda030870a2054e18e6270477e4d6506ca8.gif)

---

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [November 27, 2022, 11:02pm UTC](https://discourse.processing.org/t/bug-touches-array-sometimes-doesnt-remove-objects-if-touch-has-ended/39892/7 "2022-11-27T23:02:09Z")

</div>

it only “works” if the first finger isn’t moved.  
On my mom’s Galaxy A5 2016 it was a bit difficult as even if I didn’t move my finger, it sometimes moved the detected touch of that first finger.
