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]
java.lang.NullPointerException
at com.jme3.texture.image.ByteOffsetImageCodec.writeComponents(ByteOffsetImageCodec.java:85)
at com.jme3.texture.image.DefaultImageRaster.setPixel(DefaultImageRaster.java:109)
at com.zero_separation.plugins.imagepainter.ImagePainter.paintPixel(ImagePainter.java:528)
at com.zero_separation.plugins.imagepainter.ImagePainter.paintRect(ImagePainter.java:369)
at mygame.MapAppState.update(MapAppState.java:71)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:261)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)[/java]
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]
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 …
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?
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.
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.
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…