java.lang.ArrayIndexOutOfBoundsException: 0 on loadPixels()

edited April 2014 in Hello Processing

If i use loadPixels() in setup it's fine. If i use it in draw i get a IndexOutOfBoundsException: 0. Am i doing something wrong?

PImage img;

void setup() {
  img = loadImage("test_02.png");
  size(img.width, img.height, OPENGL);
  // here it's fine
  img.loadPixels();

}


void draw() {
 image(img, 0, 0); 

 // here index out of bounds
 //img.loadPixels();

 text(frameRate, 20, 20);
}

Answers

  • yes.

    move loadImage() after size() - the data paths don't get initialized until size() is called

    size() should be the first thing in setup().

  • I always recommend to use

    loadImage after size (since without size processing doesn't know the path)

    maybe that has an impact on loadPixels ?

  • I am too late...

    then you need to put the values for size in manually from the image

  • I used it like that so many times and it always worked. Anyway, i moved it after size but i still have the problem.

    PImage img;
    
    void setup() {
      size(1500, 750, OPENGL);
      img = loadImage("test_02.png");
      //size(img.width, img.height, OPENGL);
      // here it's fine
      img.loadPixels();
    
    }
    
    
    void draw() {
     image(img, 0, 0); 
    
     // here index out of bounds
     img.loadPixels();
    
     text(frameRate, 20, 20);
    }
    

    Here the image:

    test_02

  • edited April 2014

    It's working fine for me @ Processing 2.0.2 w/ 64-bit OpenJDK 7.51 in Lubuntu 13.04!

  • edited April 2014

    hmm...

    probably it's no good to do it 60 times per second anyway...

    you should load it only when it changes

    maybe set your memory higher in the preferences?

  • Mine is set to 1024 MiB btW! o->

  • Mine is set to 2048. If i set the framerate to 1 i still have the problem. I also made a small image of 512x256 but still the error. I'm on processing 2.1.2 on max os x 10.9.2.

    Here is the complete log:

    java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 0
        at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
        at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
        at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
        at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
        at javax.media.opengl.Threading.invoke(Threading.java:191)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
        at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
        at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
        at processing.core.PApplet.run(PApplet.java:2254)
        at java.lang.Thread.run(Thread.java:744)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at processing.opengl.Texture.convertToRGBA(Texture.java:1078)
        at processing.opengl.Texture.set(Texture.java:348)
        at processing.opengl.PGraphicsOpenGL.updateTexture(PGraphicsOpenGL.java:6257)
        at processing.opengl.PGraphicsOpenGL.getTexture(PGraphicsOpenGL.java:6122)
        at processing.opengl.PGraphicsOpenGL$TexCache.getTexture(PGraphicsOpenGL.java:6914)
        at processing.opengl.PGraphicsOpenGL.flushPolys(PGraphicsOpenGL.java:2464)
        at processing.opengl.PGraphicsOpenGL.flush(PGraphicsOpenGL.java:2415)
        at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1712)
        at processing.core.PApplet.handleDraw(PApplet.java:2404)
        at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
        at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
        at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
        at java.awt.EventQueue.access$200(EventQueue.java:103)
        at java.awt.EventQueue$3.run(EventQueue.java:694)
        at java.awt.EventQueue$3.run(EventQueue.java:692)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
    
  • It only happens in OpenGL, i will report it as a issue on github.

  • Use Processing v2.0.3 for now! ;;)

  • Ok good to know. Why do you use 2.0.2 btw and not 2.1.2?

  • edited May 2014

    Only when I see a version where folks stop complaining about nasty bugs I take the courage to finally upgrade! ;)
    Actually I coulda been using v2.0.3. But the diffs. are so lil' from v2.0.2 that I didn't bug to upgrade to! :P

  • I believe 2.03 was the most bugged for me (OpenGl speaking). My memory was always filling like a counter until it was out of memory.

  • 95% I use JAVA2D! @-)

  • I think i will follow you with that :) https://github.com/processing/processing/issues/2494

    p.s. codeanticode in case you ever watch this. I love the work you're doing and i'm amazed by the performance of processing with OpenGL!

Sign In or Register to comment.