Code stops working when creating large arrays

Hey everyone,
I am working on a pc temperature/RAM monitor which i wan’t to display on a OLED screen. A program i wrote in c# sends data to the arduino via the serial port. That’s all working well but now i want to include a graph on the OLED screen. this graph has to move to the left as more data is being added ( just like the graphs in task manager). I have to use a circular array for this to keep adding data to the end of the array en remove data from the beginning so that my values shift to the left every time. Now the problem is that whenever I add an array the OLED just stops working.

void Shift(int val){                            //Array1 is the array of which i want to shift values            
    int array2[63];                               //This is a temporary array
    for(int i = 0; i < 62; i++){                   //Move everything from array1 to array2 but shift every value to the left.
        array2[i] = array1[i+1];
        }
    for(int i = 0; i < 62; i++){                 //Copy the array back to array1 
        array1[i] = array2[i];
        }
    array1[62] = val;                                //add the new value to the array. 
}

This is the function i wrote to shift the data in the array. Now whenever I call this function, even if i call it in the setup for example, the oled doesnt update anything anymore. Even when i just call the function and I dont even use the array.

The code is still running, for example if i write:

Serial.print("A");
Shift(3);
Serial.print("B");

I see AB in the serial monitor so the code still continues but the OLED becomes completely useless.
I tried this on a Arduino UNO and NANO and they both show the same problem.

Here is my complete code if neccessary:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

char character;
String data = "";
String indata = "";
int val = 0;
int array1[63];

void setup() {
  Serial.begin(9600);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  
  display.invertDisplay(true);
  delay(500);
  display.invertDisplay(false);
  
  display.drawLine(0,0,0,50,WHITE); 
  display.drawLine(0,50,64,50,WHITE);
  
  display.drawLine(64,0,64,50,WHITE);
  display.drawLine(64,50,128,50,WHITE);
  display.drawLine(127,50,127,0,WHITE);

  display.setTextColor(WHITE, BLACK); // Draw white text
  display.setTextSize(1);
  display.cp437(true); // Normal 1:1 pixel scale
  
  display.display();
}

void loop() {
  while(Serial.available() > 0){
    character = Serial.read();
    indata += character;
  }
  if(indata.indexOf("&") != -1){
  clearinfo(false);
  
  display.setCursor(1,54);
  display.print("CPU: " + extractval(indata, "0", "*") + char(248) + "C");
  val = 100 - extractval(indata, "0", "*").toInt();
  val = map(val, 0, 100, 0, 50);
  
  display.setCursor(67,54);
  display.print("GPU: " + extractval(indata, "*", "#") + char(248) + "C");
  Serial.print(extractval(indata, "*", "#"));


  display.display();
  indata = "";
  }
}



String extractval(String input, String c1, String c2){
  if(c1 != "0"){
    input.remove(0,input.indexOf(c1)+1);
  }
  input.remove(input.indexOf(c2));
  input.trim();
  return input; 
}

void clearinfo(bool Update){
  display.fillRect(0, 51, 128, 64, BLACK);
  display.fillRect(1, 0, 63, 50, BLACK);
  if(Update){
    display.display();
  }
}

void Shift(int val){
    int array2[63];
    for(int i = 0; i < 62; i++){
        array2[i] = array1[i+1];
        }
    for(int i = 0; i < 62; i++){
        array1[i] = array2[i];
        }
    array1[62] = val;
}

I have no idea why this is happening and how to solve it… Hope you guys can help,
Gustav

is that really your code?
I don't see where your call Shift
or where you use the content of array1

(beside that, the temporary copy shift into array2 is not necessary anyway, and the "copy" would be better done with memcpy, if this shifting is really necessary at all...)

activate the compiler warnings. Any reports?
And show us the result of your memory usage as reported from the compiler.
You have to enshure that you have got enough SRAM left during runtime to waste 63*2 local bytes.

Do you really have to keep copying the data from one array to another ?

Why not have variables holding the head and tail indices of the data to be displayed and add the new data to the next position in the array, overwriting the previous value, update the indices and display the data starting at the head position and ending at the tail position ?

When the head or tail values move outside of the array bounds then reset the index value to zero to make it wrap around

noiasca:
is that really your code?
I don't see where your call Shift
or where you use the content of array1

(beside that, the temporary copy shift into array2 is not necessary anyway, and the "copy" would be better done with memcpy, if this shifting is really necessary at all...)

activate the compiler warnings. Any reports?
And show us the result of your memory usage as reported from the compiler.
You have to enshure that you have got enough SRAM left during runtime to waste 63*2 local bytes.

I don't get any warnings (I set compiler warnings to 'all'), Im using 54% of program storage and 27% of dynamic memory. Yes i didn't call the function in the code i included. This is simply because i haven't come that far, it doesn't matter where i call the function, it always results in the same problem. And I also dont use array1 yet. I know this is probably a inefficient piece of code, i first used a circularbuffer library but it got the same problem. (GitHub - rlogiacco/CircularBuffer: Arduino circular buffer library). Im gonna experiment a bit with the advise of UKHeliBob, I think i'm just using too much RAM altough its not shown anywhere...

the compiler shows you only the static memory (global variables and static variables), not the array2 in local scope. The oled might need more stack and/or heap which might be the reason unforeseeable behavior.

And by the way, check if you really need an int … do you get large numbers including negative ones? Or are you happy with 0…255 (1 Byte)?

This might avoid your local variable:

void Shift(int val){
    for(int i = 0; i < 62; i++){
        array1[i] = array1[i+1];
        }
    array1[62] = val;
}

if 63 is to large, do a test with a smaller buffer also.

but as already pointed out, use a (self written) circular buffer.

Something along the lines of this example perhaps

byte anArray[8] = {0};
byte head = 0;
byte tail = 7;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
}

void loop()
{
  outputArray();
  byte newValue = random(200) + 10;
  anArray[tail] = newValue;
  tail++;
  if (tail >= 8)
  {
    tail = 0;
  }
  head++;
  if (head >= 8)
  {
    head = 0;
  }
  delay(1000);
}

void outputArray()
{
  for (int index = 0; index < 8; index++)
  {
    Serial.print(anArray[(head + index) % 8]);
    Serial.print("\t");
  }
  Serial.println();
}

noiasca:
the compiler shows you only the static memory (global variables and static variables), not the array2 in local scope. The oled might need more stack and/or heap which might be the reason unforeseeable behavior.

And by the way, check if you really need an int … do you get large numbers including negative ones? Or are you happy with 0…255 (1 Byte)?

This might avoid your local variable:

void Shift(int val){

for(int i = 0; i < 62; i++){
       array1[i] = array1[i+1];
       }
   array1[62] = val;
}




if 63 is to large, do a test with a smaller buffer also.

but as already pointed out, use a (self written) circular buffer.

So i tried this today and thanks, i can now use up to two buffers (i only need numbers from 0 to 50). But I actually need 4 buffers… I still need to try the advise UKHeliBob gave so hopefully it gets me a bit further. Thanks for the help guys.
Gustav