# Map function worked in Processing 2 and early 3.. But broke in 3.5.3. Need guidance

**URL:** https://discourse.processing.org/t/map-function-worked-in-processing-2-and-early-3-but-broke-in-3-5-3-need-guidance/11371
**Category:** Electronics (Arduino, etc.)
**Created:** [May 18, 2019, 10:16pm UTC](https://discourse.processing.org/t/map-function-worked-in-processing-2-and-early-3-but-broke-in-3-5-3-need-guidance/11371 "2019-05-18T22:16:38Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 18, 2019, 10:54pm UTC](https://discourse.processing.org/t/map-function-worked-in-processing-2-and-early-3-but-broke-in-3-5-3-need-guidance/11371/2 "2019-05-18T22:54:51Z")

</div>

- Mutating the sketch’s main canvas outside the “Animation Thread” crashes the program! 💥
- Callback **serialEvent()** is run by the Serial’s Thread btW. ⚠
- So even calling something like **background()** can be fatal! 😨
- Actually, due to a bad design, any Processing function which depends on **color()** will get wrong results when they’re multithreading invoked! 🐛
- So any canvas mutating operations should be moved to **draw()** or called by it. 🧐
- Here’s a post link for a bare minimum Serial data receiver demo: 👼

- [Forum.Processing.org/two/discussion/14534/myport-available-always-0#Item\_1](http://Forum.Processing.org/two/discussion/14534/myport-available-always-0#Item_1)

```auto
/**
 * Efficient Serial Reading (v1.02)
 * GoToLoop (2016-Jan-19)
 *
 * Forum.Processing.org/two/discussion/14534/
 * myport-available-always-0#Item_1
 *
 * Forum.Processing.org/two/discussion/16618/
 * processing-with-arduino-void-serialevent#Item_5
 *
 * Discourse.Processing.org/t/
 * map-function-worked-in-processing-2-and-early-3-
 * but-broke-in-3-5-3-need-guidance/11371/2
 */
 
import processing.serial.Serial;
 
static final int PORT_INDEX = 0, BAUDS = 9600;
String myString = "";
 
void setup() {
  noLoop();
  final String[] ports = Serial.list();
  printArray(ports);
  new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER);
}
 
void draw() {
  println(myString);
}
 
void serialEvent(final Serial s) {
  myString = s.readString().trim();
  redraw = true;
}

```

---

_[View the full topic](https://discourse.processing.org/t/map-function-worked-in-processing-2-and-early-3-but-broke-in-3-5-3-need-guidance/11371)._
