# Clip function crashes live html canvas (unresolved)

**URL:** <https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150>\
**Category:** Coding Questions\
**Created:** [July 29, 2022, 5:13pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150 "2022-07-29T17:13:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)\
**Post date:** [July 29, 2022, 5:13pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/1 "2022-07-29T17:13:45Z")

</div>

not sure quite how to even phrase this question but i’m trying to use the clip function and it works fine on local processing, but in my live html canvas (with processing.js) invoking it in any capacity, even just using noClip(); immediately breaks the program. no error no way to debug it at all. it’s definitely clip that’s doing this. any guidance? thanks

here’s some relevant code:

```auto
<!doctype html>
<html>
<head>
<meta charset="utf-8">
	<title>pde test</title>
	<script type="text/javascript" src="processing.js"></script>
	<link rel="stylesheet" href="index.css">
</head>

<body>
	<canvas data-processing-sources="topdown_engine.pde camera.pde grid.pde scene.pde tile.pde sprite.pde"></canvas>
</body>
</html>

```

```auto
/* @pjs preload="data/tall_tex.png"; */

Scene scene;
int TICK;

void setup(){
  size(750,750);
  noClip(); //adding this line makes the canvas immediately go blank, commenting it out fixes it
  noSmooth();
  colorMode(HSB);
  
  loadTextures();
  
  TICK = 0;

  scene = new Scene();
  
}

void draw(){
  runGameTEMP();
  
  noSmooth();
  image(scene.render(500,500),0,0,width,height);

  TICK++;
}

void runGameTEMP(){
  //scene.mainCam.x=(mouseX-width/2)/55.0;
  //scene.mainCam.y=(height/2-mouseY)/55.0;
  
  //scene.mainCam.x=sin(TICK*0.05)*2;
  //scene.mainCam.y=cos(TICK*0.025)*2;
  
  if(mousePressed){
    float[] mpos = scene.mainCam.tileAt(mouseX*((float)scene.mainCam.pw/width),mouseY*((float)scene.mainCam.ph/height),0);
    scene.player.x=mpos[0];
    scene.player.y=mpos[1];
  }
  for(int i = 1;i < scene.sprites.size();i ++){
    scene.sprites.get(i).z=sin(TICK*0.025)+0.5;
  }

  scene.mainCam.x+=(-scene.player.x-scene.mainCam.x)*0.025;
  scene.mainCam.y+=(-scene.player.y-scene.mainCam.y)*0.025;
}

```

here’s what my canvas looks like when i invoke clip

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/4/0455060722cfa60ea9c7e2b64d8009c03fe26d23.png)

do i just need to import this somehow? it’s like it doesn’t recognize it at all. again this works totally fine in a local processing sketch, just not in html

---

<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:** [July 29, 2022, 5:30pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/2 "2022-07-29T17:30:16Z")

</div>

Hi @canslp,

Don’t stick on processing.js too much. It’s no future tech. If you want to provide your stuff to the web, it would be better to use p5js. Don’t know your expertise but it is imo not that hard to translate the processing java to p5js… You should give it a try …

Cheers,  
—mnse

---

<div class="post-metadata">

**Author:** ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)\
**Post date:** [July 30, 2022, 12:22am UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/3 "2022-07-30T00:22:02Z")

</div>

which one is faster for graphics, that’s my main priority atm

---

<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:** [July 30, 2022, 7:33am UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/4 "2022-07-30T07:33:25Z")

</div>

Hi @canslp,

when comparing processingjs to p5js, I would strongly assume that the latter is far more optimized in terms of browser compatibility and performance. Especially since both are based on javascript. It’s not like you could compare it with processing java.

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)\
**Post date:** [July 30, 2022, 3:08pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/5 "2022-07-30T15:08:10Z")

</div>

oh is p5js weakly typed. is there like a version of it that is strongly typed

---

<div class="post-metadata">

**Author:** ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)\
**Post date:** [July 30, 2022, 3:26pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/6 "2022-07-30T15:26:59Z")

</div>

fwiw i would still like to know if the clip function can work in html and if not what i should do instead

---

<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:** [July 30, 2022, 4:06pm UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/7 "2022-07-30T16:06:04Z")

</div>

Hmmm!

I can’t find the noClip function in processing.js at all !?  
Looks to me as it is not implemented for processing.js…

Have you checked your console output when running with noClip if your sketch is running or throws errors !?

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)\
**Post date:** [July 31, 2022, 2:19am UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/8 "2022-07-31T02:19:13Z")

</div>

well the console doesn’t really ever throw errors in the html side. again clip and noClip both work in processing (the side that throws errors). i think you are right that for some reason the html interpreter just does not have this thing

---

<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:** [July 31, 2022, 8:29am UTC](https://discourse.processing.org/t/clip-function-crashes-live-html-canvas-unresolved/38150/9 "2022-07-31T08:29:14Z")

</div>

Hi @canslp,

I’ve now checked this on my box. Unfortunately I had only mobile access to it the last days …  
But when I tried it the console now it clearly says:

> ReferenceError: noClip is not defined

and so for sure the processing bail out …

Cheers  
— mnse

PS: Also I made a quick example [here](https://editor.p5js.org/mnse_forum/full/_RssvUM12) how to do fast clipping with p5js+shader
