# PShape setStrokeWeight setStroke error

**URL:** <https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 27, 2022, 6:12pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147 "2022-05-27T18:12:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erif/32/15932_2.png) [@Erif](https://discourse.processing.org/u/Erif)\
**Post date:** [May 27, 2022, 6:12pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/1 "2022-05-27T18:12:29Z")

</div>

Hi all. I’ve come across an issue where after creating a PShape shape: .setStroke, .setStrokeWeight, shape.Stroke() and shape.strokeWeight() were throwing a GLException: GLBufferObjectTracker.mapBuffer() error.

Here’s the code as per the standard examples found online and then below how I managed to solve it.  
This one produces the error!

```auto
PShape star;

void setup() {
  size(500,500,P2D);
  
  star = createShape();
  
  star.setFill(false);
  star.setStrokeWeight(2);
  star.setStroke(color(0));
  
  star.beginShape();

  float x = 0;
  for(float i = 0; i < radians(360); i+= 0.1) {
    star.vertex(x,100*sin(i));
    x += 5; 
  }
  star.endShape(CLOSE);
}

void draw() {
  background(255);
  translate(0,height/2);
  shape(star);
}

```

---

<div class="post-metadata">

**Author:** ![Erif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erif/32/15932_2.png) [@Erif](https://discourse.processing.org/u/Erif)\
**Post date:** [May 27, 2022, 6:15pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/2 "2022-05-27T18:15:28Z")

</div>

By not specifying a P2D environment -remove P2D from size()- then it renders perfectly!!! 😅

```auto
PShape star;

void setup() {
  size(500,500);
  
  star = createShape();
  
  star.setFill(false);
  star.setStrokeWeight(4);
  star.setStroke(color(0));
  
  star.beginShape();
  
  float x = 0;
  for(float i = 0; i < radians(360); i+= 0.1) {
    star.vertex(x,100*sin(i));
    x += 5; 
  }
  star.endShape(CLOSE);
}

void draw() {
  background(255);
  translate(0,height/2);
  shape(star);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 27, 2022, 7:50pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/3 "2022-05-27T19:50:39Z")

</div>

Hello,

I did not have any errors with Processing 3.5.4 or 4.0b8 on a Windows 10 PC with an NVIDIA card.

I have encountered issues between renderers at times in the past.

What is your programming environment?

You are using a _floating point loop_.

Google search on floating point loop:  
[https://www.google.com/search?q=floating+point+loop](https://www.google.com/search?q=floating+point+loop)

Consider using an integer loop after doing some research:

```auto
for(int i= 0; i<360; i++)
  {
  float angle = radians(i);
  println(i, angle);
  }

```

`:)`

---

<div class="post-metadata">

**Author:** ![Erif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erif/32/15932_2.png) [@Erif](https://discourse.processing.org/u/Erif)\
**Post date:** [May 27, 2022, 9:47pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/4 "2022-05-27T21:47:48Z")

</div>

Hi @glv,

I’m using Processing 4.0b3 on a Macbook Pro with Radeon Pro 450 2 GB and Intel HD Graphics 530 1536 MB chipset.  
I’ll have a look at the floating point loop, thanks for your suggestion! 🙂

Cheers

---

<div class="post-metadata">

**Author:** ![Erif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erif/32/15932_2.png) [@Erif](https://discourse.processing.org/u/Erif)\
**Post date:** [May 29, 2022, 3:48pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/5 "2022-05-29T15:48:04Z")

</div>

Following up on this… 🤔 Could someone please try to see if the following code loads on your end?  
If I keep the P2D renderer for texture() to work I would get an error, and if I remove it for the polygon properties to work then texture() would not load 😩.

```auto
Wiggler w;
PImage flag;

void setup() {
  size(800,800,P2D);
  w = new Wiggler();
}

void draw() {
  w.display();
  w.wiggle();
}

class Wiggler {
  //The PShape to be wiggled
  PShape spain;
  //It's location
  float x,y;
  
  Wiggler() {
    x = width/2;
    y = height/2;
    
    spain = createShape();
  
    spain.beginShape();
    
    flag = loadImage("spain-flag.jpg");
    texture(flag);
  
    spain.noFill();
    spain.stroke(255);
    spain.strokeWeight(3);
    
    //draw Spain as a polygon and distort the flag inside the polygon
    spain.vertex(100,-250,480,0);
    spain.vertex(-250,-250,0,160);
    spain.vertex(-250,-150,0,240);
    spain.vertex(-150,-150,0,240);
    spain.vertex(-150,150,0,600);
    spain.vertex(-50,250,360,800);
    spain.vertex(0,200,400,800);
    spain.vertex(150,150,520,800);
    spain.vertex(250,50,800,440);
    spain.vertex(200,0,800,400);
    spain.vertex(300,-250,800,160);
  
    spain.endShape(CLOSE);
  }
  
  void wiggle() {
    //To iterate over the vertices of a PShape, you can loop from 0 to the total number
    //of vertices (getVertexCount()). Assuming a PShape "s", this would look something
    //like:
    for(int i = 0; i < spain.getVertexCount(); i++) {
      //The vertices can be retrieved as PVector objects with getVertex().
      PVector vspain = spain.getVertex(i);
      //You could then move that vertex by manipulating the PVector and setting new
      //values with setVertex().
      vspain.x += random(-0.5,0.5);
      vspain.y += random(-0.5,0.5);
      spain.setVertex(i,vspain.x,vspain.y);
    }
   }
  void display() {
    pushMatrix();
    translate(x,y);
    shape(spain);
    popMatrix();
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 29, 2022, 5:32pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/6 "2022-05-29T17:32:39Z")

</div>

Hello,

I did not get an image to texture with your code and it was just a white fill.

My exploration of this:

```auto
PImage flag;

PShape spain;

void setup() 
  {
  size(800,800,P2D);
 // Always a good idea to preload images in setup; especially if loading them from a link. You only want to do this once!  
 flag = loadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Processing_3_logo.png/240px-Processing_3_logo.png");
  
  spain = createShape();

  spain.beginShape();
  
  spain.texture(flag); // I changed this !

  spain.noFill();
  spain.stroke(255);
  spain.strokeWeight(3);
  
  //draw Spain as a polygon and distort the flag inside the polygon
  spain.vertex(100,-250,480,0);
  spain.vertex(-250,-250,0,160);
  spain.vertex(-250,-150,0,240);
  spain.vertex(-150,-150,0,240);
  spain.vertex(-150,150,0,600);
  spain.vertex(-50,250,360,800);
  spain.vertex(0,200,400,800);
  spain.vertex(150,150,520,800);
  spain.vertex(250,50,800,440);
  spain.vertex(200,0,800,400);
  spain.vertex(300,-250,800,160);

  spain.endShape(CLOSE);
  }

void draw() 
  {
  background(128);
  if (mousePressed) 
    {
    textureWrap(REPEAT); 
    } 
  else 
    {
    textureWrap(CLAMP);
    }
  shape(spain, width/2, height/2);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/9/89f89b058d1f2a90afbc88b01312c04999b7ac1b.jpeg)

`:)`

---

<div class="post-metadata">

**Author:** ![Erif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erif/32/15932_2.png) [@Erif](https://discourse.processing.org/u/Erif)\
**Post date:** [May 29, 2022, 7:36pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/7 "2022-05-29T19:36:59Z")

</div>

A straight copy/paste from your code gives me the same error:

“GLException: GLBufferObjectTracker.mapBuffer(): GL\_INVALID\_VALUE Invalid values: offset 0, length 0, buffer storage of target 0x8892 → 10: GLBufferStorage[name 10, size 0, mutable usage 0x88E8, mapped null]”

Could it be my version of Processing? 4.0b3

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 29, 2022, 7:46pm UTC](https://discourse.processing.org/t/pshape-setstrokeweight-setstroke-error/37147/8 "2022-05-29T19:46:17Z")

</div>

> [@Erif](#):
>
> Could it be my version of Processing? 4.0b3

Maybe…

A quick search for the error came up with this:

> <https://github.com/benfry/processing4/issues/353>
>
> \## Description
> 
> Running the 'BeginEndContour' example included with Processing…. On Linux I get an exception.
> 
> \`\`\`
> GLException: GLBufferObjectTracker.mapBuffer(): GL\_INVALID\_VALUE Invalid values: offset 0, length 0, buffer storage of target 0x8892 -\> 10: GLBufferStorage\[name 10, size 0, mutable usage 0x88E8, mapped null\]
> \`\`\`
> 
> \## Your Environment
> 
> Using the official binary download.
> 
> \* Processing version: 4.0b3
> \* Operating System and OS version: Debian 11
> \* Other information: Wayland
> 
> \`\`\`
> $ uname -a
> Linux aleph 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86\_64 GNU/Linux
> \`\`\`

`:)`
