processing / processing/processing4

noStroke makes PShape.setTexture crash (P2D)

Open
#695 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted opengl
Dominant language
Java
Stars
494
Forks
183
Avg merge
4h 39m
Merged PRs (30d)
3

Description

Created by: TidensBarn

I had inexplicable crashes when using textures on PShapes that almost made me loose my will to live until I finally found the cause:
If I create a PShape in "noStroke" state, setTexture will work the first time, but when I then try to set a different texture and redraw, it'll crash:

    PShape shape;
    
    void settings() {
      size(400, 400, P2D); 
    }
    
    void setup() {
    }
  
    void draw() {

      noStroke(); // Remove this, no crash

      shape = createShape(RECT, 0, 0, 200, 200);
      
      PImage p1 = loadImage("img1.png");
      shape.setTexture(p1);
      shape(shape);
      
      PImage p2 = loadImage("img2.png"); // p2 needs to be a different size from p1
      shape.setTexture(p2);
      shape(shape); // Crash!
    }

It's an ArrayIndexOutofBoundsException in PShapeOpenGL, line 843, because the field "firstLineVertex" happens to be -1...
Here's a sketch with images: crash.zip
Tested on Win 10, Processing 4.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied crash sketch and inspect PShapeOpenGL around line 843, where firstLineVertex is reported as -1. Reproduce the failure in P2D with noStroke(), then replace a shape's texture with an image of a different size and redraw it. Done means this sequence no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.