processing sketch throwing java.lang.AssertionError only when fill() is used

July 07, 2019, at 10:10 PM

The study project is about warping text along bezier curves(recursive polynomial form) on processing using the geomerative library to get shape from a .ttf type font file.(It needs a ttf file in the data directory to function.) currently, the sketch seems to throws errors when fill(any color); is used at the part where the code draws the character shapes and the bezier curve's length gets shorter than a certain length. If fill(); is not used, the sketch seems to function okay without any errors. The goal is to use the fill(); function to fill the characters without errors.

I've tried; 1) getting rid of the beginContour(); and endContour(); because I thought it hasn't been written properly.(I thought it was wrong because the contours should only be drawn when the shape is the inner side of a letter but currently, it draws contours when it's not the first or last shape) But the sketch throws errors even when the contour function was not used (fill(); was used). 2) thought it had something to do with the length of the curve, so tried to add a if statement to the part where it draws the letters. So far, I've tried using the width of the RGroup generated from the initial font size and string in void setup(){}, and the length of the bezier curve. The condition examples within the if statement was as follows; -draw letters when the RGroup shape's width is smaller than the length of the curve -draw letters when the "indent"(a variable to calculate the position on the curve) value is smaller than the length of the curve. (this case made the sketch to draw letters only when the letters were placed within the curve, but the error still occurred) -draw letters when the "indent"(a variable to calculate the position on the curve) value is smaller than the width of the RGroup.

I've failed to see where exactly the problem is occurring, so I'm sharing the entire code within the sketch, but I marked the spot where I presume the error is happening with "//*******".

This study was based on the following link. The geomerative library documentation can be seen from the following link.

//build a bezier curve using the recursive polynomial form
//number of control points(num+1 points)
int num = 4;
//arraylist to store the picked values
ArrayList<Point> pt;
float nfac;
import geomerative.*;
RFont fnt;
RGroup rg;
RPoint [][]rp;
String str = "(O_o)/ Oooh";
FloatList X;
FloatList Y;
FloatList SUM;
void setup(){
  pt = new ArrayList<Point>();
  //pick a number of points with random positions and store x,y values in them
  for(int i=0; i<=num; i++){
    float x = random(0,width);
    float y = random(0,height);
    pt.add(new Point(x,y));
  fnt = new RFont("Zapfino.ttf",100);
  rg = fnt.toGroup(str);
  rp = rg.getPointsInPaths();
  X = new FloatList();
  Y = new FloatList();
  SUM = new FloatList();
void draw(){
  //draw points
  for(int i=0; i<=num; i++){
  for(int i=0; i<=num; i++){

  //draw curve
  nfac = 1;
  for(int i=0; i<num; i++){
    nfac *= (i+1);
  int Bzindex = 0;
  for(float t=0; t<=1; t+=0.01){
    float x = 0;
    float y = 0;
    for(int i=0; i<=num; i++){
      float coef = 1;
      float kfac = 1;
      float k_nfac = 1;
      for(int k=i; k>0; k--){
        kfac *= k;
      for(int k=(num-i); k>0; k--){
        k_nfac *= k;
      coef = nfac/(kfac*k_nfac);
      x += coef*(pow((1-t),num-i)*pow(t,i)*pt.get(i).x);
      y += coef*(pow((1-t),num-i)*pow(t,i)*pt.get(i).y);

  //get arclength by pulling points from a floatlist
  int numberOfDivisions = X.size()-2;
  int maxPoint = numberOfDivisions+1;
  float sum = 0;
  float prevPointX = X.get(0);
  float prevPointY = Y.get(0);
  for(int i=1; i<=maxPoint; i++){
    float pointX = X.get(i);
    float pointY = Y.get(i);
    sum += dist(pointX,pointY,prevPointX,prevPointY);
    prevPointX = pointX;
    prevPointY = pointY;
  //creates error only when using fill();
  float indent = SUM.get(0);
  for(int i=0; i<rp.length; i++){
    for(int j=0; j<rp[i].length; j++){
      float t = 0;
      indent = rp[i][j].x+SUM.get(0);
      float targetArcLength = indent;
        int index = IndexOfLargestValueSmallerThan(targetArcLength);
          t = index/(SUM.size()-1);
          float lengthBefore = SUM.get(index);
          float lengthAfter = SUM.get(index+1);
          float segmentLength = lengthAfter - lengthBefore;
          float segmentFraction = (targetArcLength - lengthBefore)/segmentLength;
          t = (index+segmentFraction)/(SUM.size()-1);
        float x = 0;
        float y = 0;
        float vx = 0;
        float vy = 0;
          for(int l=0; l<=num; l++){
            float coef = 1;
            float kfac = 1;
            float k_nfac = 1;
            for(int k=l; k>0; k--){
              kfac *= k;
            for(int k=(num-l); k>0; k--){
              k_nfac *= k;
            coef = nfac/(kfac*k_nfac);
            x += coef*(pow((1-t),num-l)*pow(t,l)*pt.get(l).x);
            y += coef*(pow((1-t),num-l)*pow(t,l)*pt.get(l).y);
            float v = (pow(1-t,num-l)*l*pow(t,l-1))+((num-l)*pow(1-t,num-l-1)*(-1)*pow(t,l));
            vx += coef*pt.get(l).x*(v);
            vy += coef*pt.get(l).y*(v);
        PVector P = new PVector(x,rp[i][j].y+y);
        PVector ldir = new PVector(P.x-x,P.y-y);

        PVector dir = new PVector(vy,-vx); 
int IndexOfLargestValueSmallerThan(float _targetArcLength){
  int index = 0;
  for(int i=0; i<SUM.size()-1; i++){
      index = i;
  return index;
void mouseDragged(){
  int which = -1;
  for(int i=0; i<=num; i++){
      which = i;
class Point{
  float x,y;
  Point(float _x, float _y){
    x = _x;
    y = _y;
  void update(float _newx, float _newy){
    x = _newx;
    y = _newy;

Sometimes the error happens when the sketch is loaded. Most of the time, it loads okay but throws an error when you drag the point around a bit. The error code sometimes refers to the point where the control points of the curve are updated by mouse position, but because error somtimes occurs when the sketch is loaded as well, I didn't think it was a problem connected to the updated positions.

The error code is as follows;

    at processing.opengl.PSurfaceJOGL$
Caused by: java.lang.AssertionError
    at jogamp.opengl.glu.tessellator.Sweep.AddRightEdges(
    at jogamp.opengl.glu.tessellator.Sweep.SweepEvent(
    at jogamp.opengl.glu.tessellator.Sweep.__gl_computeInterior(
    at jogamp.opengl.glu.tessellator.GLUtessellatorImpl.gluTessEndPolygon(
    at com.jogamp.opengl.glu.GLU.gluTessEndPolygon(
    at processing.opengl.PJOGL$Tessellator.endPolygon(
    at processing.opengl.PGraphicsOpenGL$Tessellator.tessellatePolygon(
    at processing.opengl.PGraphicsOpenGL.tessellate(
    at processing.opengl.PGraphicsOpenGL.endShape(
    at processing.core.PGraphics.endShape(
    at processing.core.PApplet.endShape(
    at bezier_polynomial_recursive_text_03.draw(
    at processing.core.PApplet.handleDraw(
    at processing.opengl.PSurfaceJOGL$DrawListener.display(
    at jogamp.opengl.GLDrawableHelper.displayImpl(
    at jogamp.opengl.GLDrawableHelper.display(
RuntimeException: java.lang.AssertionError
    at jogamp.opengl.GLAutoDrawableBase$
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(
    at jogamp.opengl.GLDrawableHelper.invokeGL(
    at com.jogamp.newt.opengl.GLWindow.display(
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(
    at com.jogamp.opengl.util.AnimatorBase.display(
    at com.jogamp.opengl.util.FPSAnimator$
    at java.util.TimerThread.mainLoop(
Rent Charter Buses Company
When I try to display an image taken from the camera on a recyclerview, the image appears multiple lines

When I try to display an image taken from the camera on a recyclerview, the image appears multiple lines

I am working on a scavenger hunt app that displays a list of the items to photograph in a recyclerviewThe list is loaded from from Firebase

How to use different tables for entity on runtime using JPA?

How to use different tables for entity on runtime using JPA?

I am building a COTs product which records sales dataSince it will be used by different business owners i want to save the sales data to the owner specific tables

Faulty code from book on viewing bubble sort

Faulty code from book on viewing bubble sort

I am running example code from this book, Data Structures and Algorithms in Java (2nd Edition) - LaFore, that is not behaving as expectedIn the third chapter there is example code for running a visual on bubble sorts

How to pass command line arguments to Junit Test

How to pass command line arguments to Junit Test

I have a main class that accepts command line arguments and I am passing this parameter to another classNow i have to test the myClass with parameters