avoid black screen when trying to avoid out of memory.
in
Programming Questions
•
5 months ago
Hi all.
I write a code to make asynchronous loading of images in P3D context (because I will use shaders).
I call the img = null to avoid "out of memory error". but when I do this, the screen is black until the next jpeg has been loaded.
Is this possible to avoid this black screen ?
here's the code: (click in the window to load randomly images from 0 to 10. (I will need a lot of images in the future, that explains why I have to unbind them from ram, 10 is just for the example case)
main tab
I write a code to make asynchronous loading of images in P3D context (because I will use shaders).
I call the img = null to avoid "out of memory error". but when I do this, the screen is black until the next jpeg has been loaded.
Is this possible to avoid this black screen ?
here's the code: (click in the window to load randomly images from 0 to 10. (I will need a lot of images in the future, that explains why I have to unbind them from ram, 10 is just for the example case)
main tab
- /*assume that image is like = img0000.jpg, img0001.jpg…
*/
int counter =0;
PImage img;
int pos=0;
void setup()
{
size(1280 800, P3D);
}
void draw()
{
background(0);
println(frameRate);
if (img !=null)
image(img, 0, 0);
}
void mousePressed()
{
counter = int(random(10));
(new ImageLoaderThread()).start();
}
asynchronous image loder tab:
- class ImageLoaderThread extends Thread
{
public void run()
{
img =null;
try {
img = loadImage("img"+nf(counter, 4)+".jpg");
}
catch (Exception e) {
println("No Video Image: "+ e);
}
}
}
thanks in advance !
1