ImagePainter + Texture2D = NPE issue


I just install the ImagePainter plugin shared by @Zarch, and i have an issue.

If i initialize the ImagePainter with the fourth constrcutor (which let it creates the image internally) => no problem, it works
Buf if i use the first,second or third constructor (which is what i need to draw over an existing image) i have this NPE exception:

[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
at com.jme3.texture.image.ByteOffsetImageCodec.writeComponents(
at com.jme3.texture.image.DefaultImageRaster.setPixel(
at com.zero_separation.plugins.imagepainter.ImagePainter.paintPixel(
at com.zero_separation.plugins.imagepainter.ImagePainter.paintRect(
at mygame.MapAppState.update(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(

I just use the following code :
[java]ImagePainter ip = new ImagePainter(myTexture2D.getImage()); //or new ImagePainter(ImageRaster.create(myTexture2D.getImage())); or new ImagePainter(ImageRaster.create(myTexture2D.getImage(), 0));
ip.paintRect((int)(Math.random()*512), (int)(Math.random()*512), 10, 10, ColorRGBA.Green, ImagePainter.BlendMode.SET);[/java]

Any ideas?

After new tests, it seems working if i use
[java]assetManager.loadTexture("…") [/java]
…which returns a simple Texture

but not if i use a Texture2D…which is what i have in my FrameBuffer :’(.

how do you create myTexture2D?

Hum, i just do the same thing that in the renderToTexture jme3 test.

Camera myCam = new Camera(width, height);

vp = rm.createPreView(“MapViewPort”, myCam);
vp.setClearFlags(true, true, true);

myFrameBuffer = new FrameBuffer(width, height, 1);

myTexture = new Texture2D(width, height, Image.Format.RGBA8);




myCamNode = new CameraNode(“myCameraNode”, myCam);

Honestly I’m not sure what’s causing that, it’s not something I’ve ever seen happen. Do you need to generate the Image this way or can you try creating it in ImagePainter then using it?

Hum, i think it’s not relate to your code @Zarch in fact sorry to bothered you…i suspect the texture initialisation or something like that because of texture and image codecs pointed before in the stack trace.

Yeah i need to generate the image externally to your lib…to explain a bit…i’m trying to implement a minimap, so i use the testRenderToTexture to generate an image representing my terrain…and only then i need your plugin to draw over that image some icons…to show myPlayerPosition, myTargetPosition, some pnjs etc…

…unless you have a different approach to do that …

you could do the icons as quads and then just move them around - rather than redrawing/resending the image each time they change.

Yes, i’ve already thought to use this way but is it really less resources consuming?..a simple image vs a second worldRoot ?
I chose the image way because i found it more convenient and quickly doable.

About the original post, no ideas about what causes that npe?

Not a clue, sorry.

Something is set up oddly in the image which is then confusing ImageRaster… at that point it’s out of my hands and down to ImageRaster…

Yes you’re right. Maybe i’ll try to look into…if i have more time :s

Anyway, thanks for your attention @Zarch :).

I think i know what’s going on.the ByteBuffer of the image is null when you initialize the ImageRaster since the image has never been rendered.
But then the reference is never updated.

I’ll try to fix this

I committed a fix, could you please test it?

1 Like

Hey, nice catch.
After a quick peek, i think you’ve found it…your fix will surely resolve my problem. The fix doesn’t appear in today’s updates, so as soon as it pops tomorrow i’ll confirm that of course.



Ok, the buffer was null. So now it pass in your getBuffer() but image.getData(slice) return null because getData check if data.size() > index…except data is empty so size() return 0 then getData return null…and it always goes in a npe exception. The same exception of yesterday.

Why data is empty ? O_o.

Do you render the viewport?

ah…les Français… :wink:
Actually…I wonder if the data is ever filled, since the image is rendered on the GPU…
Could you wrap up a small test case?

Sorry, i don’t know what’s happened but my previous answer have disappeared when i edited it O_o

Comme tu dis ^^, après 10 ans de “pratique” tout au long de mon cursus scolaire, mon anglais est naze ! Notre système d’apprentissage des langues étrangères est vraiment à revoir…j’ai honte quand je vois des éthyopiens de 10 ans qui parlent anglais couramment…

I try to improve myself every day and discuss on this forum is a good way to start. It would be best to practise oral discussion of course but without going in the united states or in england…that’s hard…

Don’t hesitate to correct me if I express myself badly.

To go back on my problem, yes i’ll can try to extract the code and provide a little test case.

@haze said: Comme tu dis ^^, après 10 ans de "pratique" tout au long de mon cursus scolaire, mon anglais est naze ! Notre système d'apprentissage des langues étrangères est vraiment à revoir...j'ai honte quand je vois des éthyopiens de 10 ans qui parlent anglais couramment...
J'ai vu pire, t'inquiètes pas. Très souvent on peut détecter les français à la façon dont ils tournent les phrases en anglais :p. Je suis entièrement d'accord avec toi sur notre système d'apprentissage des langues en France.

Now go get that test case :wink: