Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWTException : Invalid image (How to check that an image is "valid" to avoid SWTException "Invalid image" ?)
SWTException : Invalid image [message #949778] Fri, 19 October 2012 09:30 Go to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
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 #950252 is a reply to message #949778] Fri, 19 October 2012 19:04 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
On 10/19/2012 5:30 AM, hortiz Mising name wrote:
> Is the only solution is to add a try/catch block ?

Yes, try/catch is the only way to detect this.

Are you expecting these images to always be valid (ie.- you're shipping
them all, as opposed to allowing them to come from some other
user-supplied source)? If so then perhaps you're seeing a bug in swt,
since an image that swt successfully reads once should always be
readable without problem.

Grant
Re: SWTException : Invalid image [message #950315 is a reply to message #949778] Fri, 19 October 2012 20:16 Go to previous messageGo to next message
Wojtek  is currently offline Wojtek Friend
Messages: 47
Registered: August 2011
Member
hortiz Mising name wrote :
> 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 rendering process writing to the same file as you are trying to
read? Or are you creating a temporary file then renaming it to that
file?

You may be running into a concurrency problem where the rendering
process is half way through writing to the file at the same time you
are trying to read from it.

And:
> image = new Image(parent.getDisplay(), imageName);
> testImage.dispose();

could be changed to:

image = testImage;

Which will save re-reading the file.

--
Wojtek :-)
Re: SWTException : Invalid image [message #957461 is a reply to message #950315] Thu, 25 October 2012 08:34 Go to previous message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
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
Previous Topic:SWT message queue clogged by browser messages
Next Topic:tree table flexibility
Goto Forum:
  


Current Time: Fri Apr 26 15:36:54 GMT 2024

Powered by FUDForum. Page generated in 0.03257 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top