0

I have written a method to resize an array in Java:

public HUD resize(float factor){
    int[] array = new int[(int)Math.pow(pixels.length * factor, 2)];//Create new array
    for(int y = 0; y < height; ++y){
        for(int x = 0; x < width; ++x){
            array[(int)((x * 2) + (y * 2) * width * factor)] = pixels[x + y * width];
            array[(int)((x * 2 + 1) + (y * 2) * width * factor)] = pixels[x + y * width];
            array[(int)((x * 2) + (y * 2 + 1) * width * factor)] = pixels[x + y * width];
            array[(int)((x * 2 + 1) + (y * 2 + 1) * width * factor)] = pixels[x + y * width];
        }
    }
    pixels = array;
    width = (int)(width * factor);
    height = (int)(height * factor);
    return this;
}

This method is only called once and an OutOfMemoryError is given out whenever its called

Lucas Romier
  • 1,291
  • 1
  • 13
  • 22

1 Answers1

1

Increasing the heap size of your application may prevent the OutOfMemoryError. This post on SO explains how to do this.

Community
  • 1
  • 1
StvnBrkdll
  • 3,924
  • 1
  • 24
  • 31