Hi, In a web application I'm trying to create thumbnail images on demand in response to HTTP requests. I thought I'd use Image.resize(...), only it throws No GfxEnv is active Errs.
It seems to work okay for a couple of requests but then they all fail with the same No GfxEnv is active Err. As it occurred to me that I don't know what's going on behind the scenes of Image.resize or Desktop.bounds I thought I'd ask for help!
Given each HTTP request is run in a different Actor, could it be a threading issue? If so, what would be the best way to get round it?
brianWed 22 Oct 2014
The current implementation of gfx and fwt in a JVM is backed by the SWT. The SWT is essentially a single threaded model, so there is really only thread that access to all the graphics engine. Probably the best way to try and handle is to make a call to Desktop.callAsync which will run your function on the UI thread. But in general accessing all the graphics stuff from HTTP requests can be very messy. I prototyped another version of gfx backed by AWT too, which is still messy but a little better for multi-threading.
SlimerDudeSun 26 Oct 2014
Okay thanks, I'll give that a try. I thought threads had something to do with it.
SlimerDude Mon 13 Oct 2014
Hi, In a web application I'm trying to create thumbnail images on demand in response to HTTP requests. I thought I'd use Image.resize(...), only it throws
No GfxEnv is active
Errs.So after reading the topic Font. width and "No GfxEnv is active" error I tried calling
Desktop.bounds
before each call toImage.resize()
.It seems to work okay for a couple of requests but then they all fail with the same
No GfxEnv is active
Err. As it occurred to me that I don't know what's going on behind the scenes ofImage.resize
orDesktop.bounds
I thought I'd ask for help!Given each HTTP request is run in a different Actor, could it be a threading issue? If so, what would be the best way to get round it?
brian Wed 22 Oct 2014
The current implementation of gfx and fwt in a JVM is backed by the SWT. The SWT is essentially a single threaded model, so there is really only thread that access to all the graphics engine. Probably the best way to try and handle is to make a call to Desktop.callAsync which will run your function on the UI thread. But in general accessing all the graphics stuff from HTTP requests can be very messy. I prototyped another version of gfx backed by AWT too, which is still messy but a little better for multi-threading.
SlimerDude Sun 26 Oct 2014
Okay thanks, I'll give that a try. I thought threads had something to do with it.