SWTException : Invalid image [message #949778] |
Fri, 19 October 2012 05:30  |
Eclipse User |
|
|
|
Hi,
I use several Canvas to display images from a directory.
These are grouped in a window.
These images are created by an offscreen rendering process (JOGL API) which runs in the background on my PC.
Therefore, the window containing the canvas acts as a "real time" plot viewer.
Images are generated every second, and refreshed in their canvas every 1.1 second.
The problem that I have is that sometimes the image seems to be in an invalid state and cannot be displayed ("org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Invalid image)"), but I thought that the code below would have prevented this from happening:
public void updateImage(String imageName) {
Image testImage;
testImage = new Image(parent.getDisplay(), imageName);
if (new File(imageName).exists()) {
if (image != null) { // previously displayed image
image.dispose();
}
image = new Image(parent.getDisplay(), imageName);
testImage.dispose();
}
}
How can I be sure that my image is "valid" when I call the constructor of the Image class ? Apparently, the test on the existence of the image is not sufficient.
Is the only solution is to add a try/catch block ?
Thanks,
Helene
|
|
|
|
|
Re: SWTException : Invalid image [message #957461 is a reply to message #950315] |
Thu, 25 October 2012 04:34  |
Eclipse User |
|
|
|
Hi,
Yes Grant I expect images to be valid, as the "offscreen generator" is always running.
I add a try/catch block and also (as Wojtek suggested) write in a first file and rename it when ready.
Thanks
|
|
|
Powered by
FUDForum. Page generated in 0.03375 seconds