Hello.
I am developing a small application for creating animations just for myself. I want to create the following structure: the program has folders, and those folders have layers. The program has a main folder, to which we add all other layers and folders. That is, there are two main classes: Folder and Layer.
Layer is nothing special, it just loads images, adds effects, etc.
Folder can also add effects, etc., but in addition, Folder has the following structure:
class Folder {
ArrayList<Folder> folders;
ArrayList<Layer> layers;
PGraphics pg;
public Folder() {
}
void render(PGraphics canvas) {
pg=createGraphics(canvas.width, canvas.height);
pg.beginDraw();
for (int i=0; i<folders.size(); i++) {
folder.render(pg);
}
for (int i=0; i<layers.size(); i++) {
layer.render(pg);
}
pg.endDraw();
/*
adding effects etc.
*/
canvas.image(pg);
}
}
As you can see, the problem lies in the render() method. If there are too many nested folders, there is a chance of getting an OhtOfMemoryError, which is unacceptable. How can this be avoided? It is impossible to render all folders to a single PG, as different effects are applied to them. At first, I thought about rendering the folders in stages, starting with the most recent ones, and saving the images somewhere in the application directory, but here’s the thing: if I try to load an image before it is completely saved correctly, Processing won’t give an error, it will just load the image cropped.
I’m writing code in APDE, by the way. I would be very grateful for any help!