PShape setStrokeWeight setStroke error

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!

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);
}

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

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);
}
1 Like

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

Consider using an integer loop after doing some research:

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

:)

1 Like

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! :slight_smile:

Cheers

Following up on this… :thinking: 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 :weary:.

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();
  }
}

Hello,

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

My exploration of this:

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);
  }

:)

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

Maybe…

A quick search for the error came up with this:

:)

1 Like