# macOS question pixels\[loc\] issue

**URL:** <https://discourse.processing.org/t/macos-question-pixels-loc-issue/24411>\
**Category:** Libraries\
**Created:** [October 7, 2020, 12:52pm UTC](https://discourse.processing.org/t/macos-question-pixels-loc-issue/24411 "2020-10-07T12:52:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![8SU](https://avatars.discourse-cdn.com/v4/letter/8/b4bc9f/32.png) [@8SU](https://discourse.processing.org/u/8SU)\
**Post date:** [October 7, 2020, 12:52pm UTC](https://discourse.processing.org/t/macos-question-pixels-loc-issue/24411/1 "2020-10-07T12:52:17Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

i used macOS and processing 3 ver(3.5.4)

before i have video library issue so fix that

link

> [@Did macOS Catalina (or something) break the Video library?](https://discourse.processing.org/t/did-macos-catalina-or-something-break-the-video-library/14699/16):
>
> Did you ever get this working? Just saw this looking back (someone asked elsewhere). I have a feeling editing the .info file might break the signing on the app?!

but i have one more issue

void draw() {  
//image(cam, 0, 0);

cam.loadPixels();  
prevFrame.loadPixels();

for(int x=0; x\<cam.width; x++) {  
for(int y=0; y\<cam.height; y++) {  
int loc = x + y\*cam.width;  
float r = red(cam.pixels[loc]);  
float g = green(cam.pixels[loc]);  
float b = blue(cam.pixels[loc]);  
float tr = red(prevFrame.pixels[loc]);  
float tg = green(prevFrame.pixels[loc]);  
float tb = blue(prevFrame.pixels[loc]);

```
  float d =dist(r, g, b, tr, tg, tb);
  
  if(d > 100) {
    pixels[loc] = color(255);
  } else {
    pixels[loc] = color(0); //error here
  }

  
}

```

}

updatePixels();  
}

i make that code

pixels[loc] = color(255); \<—this range is ok  
} else {  
pixels[loc] = color(0); \<---- but this range is error about “NullPointerException”  
}

how can fix this error …? help me please  
maybe i think my macOS don’t use ‘pixels[loc]’ two times  
ps. sorry my english ability is not good…

thanks

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [October 9, 2020, 7:26am UTC](https://discourse.processing.org/t/macos-question-pixels-loc-issue/24411/2 "2020-10-09T07:26:48Z")

</div>

> [@8SU](#):
>
> pixels[loc] = color(0); \<---- but this range is error about “NullPointerException”  
> }

When you work with pixel arrays (note plural) you need to be careful to reference the right pixel array. You have three pixel arrays in you’re code:

- cam.Pixels
- prevFrame.Pixels
- pixels – that is pixel array for the screen or window for processing app

You define loc from cam, if it has different height or width than display you will get “NullPointerException” when you pick a pixel on area that’s within cam area, but outside of display area.

---

<div class="post-metadata">

**Author:** ![8SU](https://avatars.discourse-cdn.com/v4/letter/8/b4bc9f/32.png) [@8SU](https://discourse.processing.org/u/8SU)\
**Post date:** [October 9, 2020, 10:39am UTC](https://discourse.processing.org/t/macos-question-pixels-loc-issue/24411/3 "2020-10-09T10:39:06Z")

</div>

thanks to answer i will must fix this issue thank you so much 😊
