Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Error disposing image resource(Got 'A factory-created resource cannot be disposed.')
Error disposing image resource [message #521035] Tue, 16 March 2010 09:53 Go to next message
Marc T. is currently offline Marc T.Friend
Messages: 17
Registered: November 2009
Junior Member
Hello,

I'm trying to display an image as Label background. Everything works fine, but when I dispose the image I get:

java.lang.IllegalStateException: A factory-created resource cannot be disposed.
at org.eclipse.swt.graphics.Resource.dispose(Resource.java:80)


My code to allocate the image is:

ImageDescriptor imgDescr = AbstractUIPlugin .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"icons/aboutdialogimage.png");

Image img=imgDescr.createImage();
...

img.dispose(); // Exception here




The javadoc for createImage() explicit states, that every call creates an new image and that the image must be released by calling dispose():

Note: this method differs from createResource(Device) in that the returned image
must be disposed directly, whereas an image obtained from createResource(...)
must be disposed by calling destroyResource(...). It is not possible to
mix-and-match. If you obtained the Image from this method, you must not dispose
it by calling destroyResource. Clients are encouraged to use
create/destroyResource and downcast the result to Image rather than using
createImage.



Any idea ?

Regards

Marc





[Updated on: Tue, 16 March 2010 09:54]

Report message to a moderator

Re: Error disposing image resource [message #521047 is a reply to message #521035] Tue, 16 March 2010 10:22 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2427
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Marc,

this is a known issue. There is already a bug opened to keep track on it:
305136: Images from Descriptor are not disposable
https://bugs.eclipse.org/bugs/show_bug.cgi?id=305136

Best,
Ivan

On 03/16/2010 11:53 AM, Marc42 wrote:
> Hello,
>
> I'm trying to display an image as Label background. Everything works
> fine, but when I dispose the image I get:
>
> java.lang.IllegalStateException: A factory-created resource cannot be
> disposed.
> at org.eclipse.swt.graphics.Resource.dispose(Resource.java:80)
>
>
> My code to allocate the image is:
>
> ImageDescriptor imgDescr = AbstractUIPlugin
> .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
> "icons/aboutdialogimage.png");
>
> Image img=imgSescr.createImage();
> ..
>
> img.dispose(); // Exception here
>
>
>
>
> The javadoc for createImage() explicit states, that every call creates
> an new image and that the image must be released by calling dispose():
>
> Note: this method differs from createResource(Device) in that the
> returned image
> must be disposed directly, whereas an image obtained from
> createResource(...)
> must be disposed by calling destroyResource(...). It is not possible
> to mix-and-match. If you obtained the Image from this method, you must
> not dispose
> it by calling destroyResource. Clients are encouraged to use
> create/destroyResource and downcast the result to Image rather than
> using createImage.
>
>
>
> Any idea ?
>
> Regards
>
> Marc
>
>
>
>
>
Re: Error disposing image resource [message #521048 is a reply to message #521035] Tue, 16 March 2010 10:35 Go to previous message
Marc T. is currently offline Marc T.Friend
Messages: 17
Registered: November 2009
Junior Member
Hello,

by further tracing into this problem I found:

- Image.dispose() is Resource.dispose().
- This throws the exception, if the property 'device' is null, which it seems to be in every case.

I tried calling createImage() with providing a device:

createImage(Display.getCurrent())


Same problem: property 'device' is still null and the exception it thrown.

The Image is somehow cached. I guess that createImage() behaves like createResource().

May be this is a bug ?

Regards

Marc
Re: Error disposing image resource [message #521133 is a reply to message #521048] Tue, 16 March 2010 09:50 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2427
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Marc,

in RAP there are two "types" of resources:
1. a factory created resources - created by Graphics.getXXX methods.
These resources are shared between the sessions and can't be disposed (
device is null ).
2. and "standard" one - created like: new Image( device, ...). Their
device is not null and you can dispose them as usual.
As I mentioned in my previous post, currently, images created from
ImageDescriptor can't be disposed (see bug 305136 ), because they are
factory created images.

Best,
Ivan

On 03/16/2010 12:35 PM, Marc42 wrote:
> Hello,
>
> by further tracing into this problem I found:
>
> - Image.dispose() is Resource.dispose().
> - This throws the exception, if the property 'device' is null, which
> it seems to be in every case.
>
> I tried calling createImage() with providing a device:
>
> createImage(Display.getCurrent())
>
>
> Same problem: property 'device' is still null and the exception it
> thrown.
>
> The Image is somehow cached. I guess that createImage() behaves like
> createResource().
>
> May be this is a bug ?
>
> Regards
>
> Marc
Previous Topic:How To Clean Launch Workspace ?
Next Topic:Reload Java Class (i.e. a ViewPart) on Runtime
Goto Forum:
  


Current Time: Tue Oct 08 23:46:42 GMT 2024

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

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

Back to the top