We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › HELP, Open Gl patch needed
Page Index Toggle Pages: 1
HELP, Open Gl patch needed (Read 725 times)
HELP, Open Gl patch needed
May 31st, 2005, 3:26pm
 
Does the code below work on anyone else's computer? It assumes there is a list of images in the data folder. Even if the list is only ten strong it crashes after uploading and displaying the 623rd frame. It's fine in P3D but runs far too slowly with the other code.

It keeps runing but displays a white applet with some white printed error about open gl bind out of memory at 0505.
Code:

import processing.opengl.*;
PImage swap;
int totalFrames = 7860;
int playhead = 1000;
void setup() {
size(800,600,OPENGL);
stepforward();
}
void draw() {
stepforward();
}
void stepforward(){
swap = loadImage("importa ("+playhead+").jpg");
render();
println(playhead);
playhead++;
if (playhead == totalFrames){
playhead = 1000;
}
}
void render(){
image(swap,0,0,width,height);
}

I am in desperate need of a patch before this thursday. Can anyone think of a work around please?
Re: HELP, Open Gl patch needed
Reply #1 - May 31st, 2005, 5:03pm
 
loading images inside draw is a very bad idea. loadImage needs to look for the image-file, open and parse it, so it's slow (you figured) ...
you could try to group (tile together) say 10 images into one big one, that way you might speed up loading time. or try "preloading" them into an array ( see here ) ...

open-GL sketches are not ment to be run as applets. that's because the openGL partly is native code, so it's not allowed to be run as unsigned applet ( see sandbox and java-security and the FAQ )

F
Re: HELP, Open Gl patch needed
Reply #2 - May 31st, 2005, 9:03pm
 
It's a projected exhibit showing at my university (It's set in present mode and left to run in a booth connected to equipment outside). Somehow running Open Gl decreases the loading time, plus seeing as I wanted an interactive webcam switch over it seemed like a good idea as it allowed a fast switch over that ran very fast. The slow speed wasn't such a bad thing until it started showing a blank screen.

P3D is immune to this error as well which was confusing.

I originally wrote off the idea of loading the images into an array as there were so many but it seems like a good tip. Dropping from 6000 to about 1000 might work (90k a pop - 90mb).

I've already boosted the memory capacity of Processing. This  ought to make a 90mb cache of images possible.

Thanks for the tip - I'll give it a go. Wink
Re: HELP, Open Gl patch needed
Reply #3 - May 31st, 2005, 9:40pm
 
just to clarify that: when talking about running as an applet i was talking about running it inside a browser ...

if speed does not matter than your code is fine and might be better than the array-approach. maybe even give the system some time to breathe by setting the framerate really low (1?).

i don't know about the out-of-mem problems you run into, ... you might call java's garbage collection once in a while, say every 200 frames:
Code:

System.gc();


and try to set swap to null before assigning it another image:
Code:

swap = null;
swap = loadImage("importa ("+playhead+").jpg");


monitor the sketch's memory consumption and see if it helps.
good luck (don't forget to post some pictures from your exhibition!),
F
Re: HELP, Open Gl patch needed
Reply #4 - Jun 1st, 2005, 1:13am
 
Nope. Neither loading frames into an array or garbage collection works.
After 623 frames Processing prints out a white error every frame (on home computer and the swish one at school):
Code:

before bind: 0505 GL_OUT_OF_MEMORY
321
before bind: 0505 GL_OUT_OF_MEMORY
322
before bind: 0505 GL_OUT_OF_MEMORY
323
before bind: 0505 GL_OUT_OF_MEMORY
324

Garbage collection makes no difference and if I try putting images into an array of substantial size I get:
Code:

44
45
46

Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space

That's with 382mb on the home computer. The exhibition space computer is much more swish and empty (given it 512mb so far) but I'm doubtful I can hammer it's memory with images. I'll still give it a shot - is there a limit to what use the memory expansion will do?

The god of code has it in for me Sad
Re: HELP, Open Gl patch needed
Reply #5 - Jun 1st, 2005, 1:58am
 
opengl is really memory hungry because of how tetxures work. in opengl mode, your images as the next power of two larger in either direction. this means an image that's 40x190 pixels will be stored as a 64x256 pixel x 4 bytes per pixel array (along with the original image storage being width x height x 4).
Re: HELP, Open Gl patch needed
Reply #6 - Jun 1st, 2005, 8:45pm
 
Can't seem to pack in more that 46 images into memory, regardless of memory settings.

Have decided that since the source images are 640,480 I'm going to run the projection at 800x600 in P3D. P3D seems pretty robust with it and runs at a resonable clunky speed at small size.

My other project is working fine in OPENGL mode - it really flies. There are no bitmaps though, just cubes. (And a world of interactive fun with a camera and microphone).

Thanks for the feedback, it was worth trying to get the image loader to work in OPENGL but it's just too problematic  what with trying to run blob detection on top. OPENGL seems to need more time to hammer out all the kinks.
Re: HELP, Open Gl patch needed
Reply #7 - Jul 16th, 2006, 7:02pm
 
Hi,

I just found this thread. I have ran into something really similar to what you're describing here. I do need to stick to OPENGL because anti-alias and transparencies are very crude in other modes. Please check this thread and if possible let me know how you solved it:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_Responsive;action=display;num=1152736596
Re: HELP, Open Gl patch needed
Reply #8 - Jul 17th, 2006, 12:12pm
 
As suggested up above in this thread, you could try System.gc to force the garbage collector but my unfortunate news is that I never solved this problem. I just ran it in P3D, which was a shame because it could have ran faster.

I tried to break P5 with this following test, but mostly it just locked up my system after 1000 iterations.
Code:

import processing.opengl.*;

PImage pimage;
int i = 0;
int count = 0;

void setup(){
size(400,400,OPENGL);
framerate(12);
}
void draw(){
pimage = loadImage("image" + i + ".gif");
image(pimage, 0, 0);
i = (i + 1) % 2;
println(++count);
}

You could perhaps rework your idea in Flash, constant image loading might be a bit more stable. Found a guide here:

http://www.kirupa.com/developer/mx2004/xml_slideshow.htm

Or you could try to get your image loading done in another thread, I believe there are posts on the forum on this subject. Some mention of it in the following url:

http://java.sun.com/developer/technicalArticles/Threads/applet/
Page Index Toggle Pages: 1