I've built a Jython swing app using eclipse and pydev. I've used simple images for the backgrounds of all of the buttons. 95% of the time, everything works wonderfully. However, about 5% of the time when adding or removing content from the screen, this occurs:
Exception in thread "AWT-EventQueue-0" at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1310)
at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1579)
at javax.imageio.ImageIO.read(ImageIO.java:1438)
at javax.imageio.ImageIO.read(ImageIO.java:1342)
at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
javax.imageio.IIOException: javax.imageio.IIOException: Error reading PNG image data
The frustrating thing is that it's not readily reproducable, and can happen anywhere in the application that I draw a PNG. I can certainly catch the exception and have it reimport the image, but I'm hoping to figure out the root cause.
I call the resources like so:
notPressed = ImageIO.read(pkg_resources.resource_stream('images', "button-blue.png")).getScaledInstance(width,height, Image.SCALE_SMOOTH )
My only guess is that sometimes pkg_resources might fail to open a filestream, causing the exception. Any suggestions on how to track this down, or should I just be happy that I can make it fail quietly?