Memory leak with img.get()?
in
Programming Questions
•
10 months ago
I have a program where I need to "tile" a texture onto a rectangle whose dimensions are not exactly dividable into the texture's dimensions. So I have to crop the image at the right and bottom edges of the rectangle since I start drawing it at the top left. But when I draw these cropped, edge images, the program runs out of memory. Here is my code:
See the continue statements? They are there so that it does not end up drawing the image after I crop it. If I remove the continue statements in the above code, my program crashes from a memory leak very quickly. If I keep the continue statements, it runs perfectly normal. Any idea on how to fix this or why this is happening?
- void drawTexture(int x, int y, int w, int h)
- {
- int imgW = img.width;
- int imgH = img.height;
- PImage imgCropped;
- PImage imgToUse = img;
- for (int i = 0; i < (w/imgW)+1; i++)
- {
- if (i >= (w/imgW)) // if its the last in the row
- {
- // println("last in the row");
- imgToUse = img.get(0,0,w-(i*imgW),imgH);
- continue;
- }
- for (int j = 0; j < (h/imgH)+1; j++)
- {
- if (j >= (h/imgH)) // if its the last in the row
- {
- imgToUse = img.get(0,0,w-(i*imgW),h-(j*imgH));
- continue;
- }
- image(imgToUse,x+(i*imgW),y+(j*imgH));
- }
- imgToUse = img;
- //imgCropped = img.get(0,0,(width-(i*imgW)),imgH);
- //image(imgCropped,x1+(i*imgW), );
- }
- //height-(j*imgH))
- // bottom right corner image
- }
1