Scoped beginDraw and endDraw

is there any way to use PGraphics.beginDraw and PGraphics.endDraw outside of the scope of PGraphics.*() calls?

for example if i do this then nothing renders

  void drawGraphics() {
    //graphics.endDraw();
    if (displayFPS) {
      window.graphics.beginDraw();
      int oldColor = window.graphics.fillColor;
      window.graphics.fill(255);
      window.graphics.textSize(16);
      window.graphics.text("FPS: " + frameRate, 10, 20);
      window.graphics.fill(oldColor);
      window.graphics.endDraw();
    }
    //graphics.beginDraw();
    graphics.image(
      window.graphics,
      window.x,
      window.y,
      window.width,
      window.height
    );
  }
  
  void drawWindow() {
    graphics.beginDraw();
    clearScreen();
    if (focus) {
      if (clickedOnBorder && locked) drawBordersLocked();
      else drawBordersHighlighted();
    } else {
      drawBorders();
    }
    drawGraphics();
    graphics.endDraw();
  }

but if i do this then it renders

  void drawGraphics() {
    graphics.endDraw();
    if (displayFPS) {
      window.graphics.beginDraw();
      int oldColor = window.graphics.fillColor;
      window.graphics.fill(255);
      window.graphics.textSize(16);
      window.graphics.text("FPS: " + frameRate, 10, 20);
      window.graphics.fill(oldColor);
      window.graphics.endDraw();
    }
    graphics.beginDraw();
    graphics.image(
      window.graphics,
      window.x,
      window.y,
      window.width,
      window.height
    );
  }
  
  void drawWindow() {
    graphics.beginDraw();
    clearScreen();
    if (focus) {
      if (clickedOnBorder && locked) drawBordersLocked();
      else drawBordersHighlighted();
    } else {
      drawBorders();
    }
    drawGraphics();
    graphics.endDraw();
  }

I don’t understand this question, in part because you have provided a code fragment and I don’t know what any of these variables are. What is “window”? What is “graphics”? What is “graphics.image()”?

In general, if you have a PGraphics object, beginDraw() initializes it for drawing – for example, allocating a buffer. endDraw() writes the buffer to the object’s internal storage. How this happens specifically depends on your renderer – e.g. JAVA2D, P2D, or P3D.

The most common problems are: if you try to draw to a PGraphics without calling beginDraw, either nothing happens or you get an error because there is no buffer. Or, if you don’t call endDraw, when you then display your PGraphics on the canvas none of your drawing is there – because you didn’t actually copy your buffer and commit your changes!