# pushMatrix() cannot use push more than 32 times

**URL:** <https://discourse.processing.org/t/pushmatrix-cannot-use-push-more-than-32-times/12860>\
**Category:** Coding Questions\
**Created:** [July 21, 2019, 11:59am UTC](https://discourse.processing.org/t/pushmatrix-cannot-use-push-more-than-32-times/12860 "2019-07-21T11:59:11Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 21, 2019, 2:05pm UTC](https://discourse.processing.org/t/pushmatrix-cannot-use-push-more-than-32-times/12860/5 "2019-07-21T14:05:25Z")

</div>

> <https://github.com/processing/processing/blob/processing-0269-3.5.3/core/src/processing/core/PGraphics.java#L530-L531>

  

> <https://github.com/processing/processing/blob/processing-0269-3.5.3/core/src/processing/awt/PGraphicsJava2D.java#L85-L86>

  

> <https://github.com/processing/processing/blob/processing-0269-3.5.3/core/src/processing/awt/PGraphicsJava2D.java#L2141-L2149>

```auto
/**
 * Change PGraphics Max Pushes (v1.0)
 * GoToLoop (2019/Jul/21)
 *
 * https://Discourse.Processing.org/t/
 * pushmatrix-cannot-use-push-more-than-32-times/12860/5
 */

import processing.awt.PGraphicsJava2D;
import java.lang.reflect.Field;

static final int PUSHES = 35, DIAM = 8, OFFSET_Y = 15;

void setup() {
  size(100, 550);
  noLoop();

  fill(#FFFF00);
  stroke(#FF0000);

  setMaxPushes((PGraphicsJava2D) getGraphics(), PUSHES);
}

void draw() {
  clear();

  for (int i = 0; i < PUSHES; ++i) {
    pushMatrix();
    translate(0, OFFSET_Y);
    square(0, 0, DIAM);
  }

  for (int i = 0; i < PUSHES; ++i) popMatrix();
}

static final void setMaxPushes(final PGraphicsJava2D pg, final int pushes) {
  try {
    final Field f = PGraphicsJava2D.class.getDeclaredField("transformStack");
    f.setAccessible(true);
    f.set(pg, expand(f.get(pg), abs(pushes)));
  }
  catch (final ReflectiveOperationException ex) {
    throw new RuntimeException(ex);
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/pushmatrix-cannot-use-push-more-than-32-times/12860)._
