Part of code that works, doesnt when added to final project (Serial COM)

My code which saves strings in a class array, sent from a COM port through an application I’ve written in visual c++, works fine when I run it standalone. When I add the code in my final project it stucks. The additional code that runs in my final code is just some pin definitions, variable declarations, and pinmode in the setup proccess.

Standalone code:

#include <stdlib.h>

class Coordinates
{
	private:
		float latitude;
		float longitude;
	public:
		void setLatitude(float aLatitude){latitude = aLatitude;}
		void setLongitude(float aLongitude){longitude = aLongitude;}
		double getLatitude(){return latitude;}
		double getLongitude(){return longitude;}
};


bool comm_done1 = false;
char buffer1[8];
char buffer2[8];
char buffer3[8];
Coordinates allCoords[7];
int times,p;




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


void loop()
{
  if(!comm_done1)
  {
      while(Serial.available() < 1 ){ }  
      buffer1[0] = Serial.read();
    
      times = atoi(buffer1)*16;
      if(times < 112)
      {
          while (Serial.available() < times){ }
          for(int j=0; j<times/16; j++)
          {
             for(int i=0; i<8; i++) buffer2[i] = Serial.read();
             for(int i=0; i<8; i++) buffer3[i] = Serial.read();
      
             allCoords[j].setLatitude(atof(buffer2));
             allCoords[j].setLongitude(atof(buffer3));
          }
      }

  else 
  {
      for(int i=0; i<10; i++) {Serial.print("Sec ");Serial.println(i);delay(1000); }
      for(int i=0;i<atoi(buffer1);i++)
      {
         Serial.print(i+1);
         Serial.print(" Lat: ");
         Serial.print(allCoords[i].getLatitude(),5);
         Serial.print(" Lon: ");
         Serial.println(allCoords[i].getLongitude(),5);
      }  
  } // else
    
} //loop

Inside the main loop I print the lat and long values every 10 secs.
Now, all that I add in the final code, are those declerations:

/*************************************************************************************************
 *                                    LIBRARIES                                                  *
 *************************************************************************************************/
#include <Wire.h>
#include <stdlib.h>
/*************************************************************************************************
 *                                    PIN SETUP                                                  *
 *************************************************************************************************/
#define motor1a 5
#define motor1b 6
#define motor2a 11
#define motor2b 12
#define pingPin 4
#define fix2DPin 8
/*************************************************************************************************
 *                                    GLOBAL VARIABLES                                           *
 *************************************************************************************************/
 class Coordinates
{
	
  private:
     float latitude;
     float longitude;
  public:
     void setLatitude(float aLatitude){latitude = aLatitude;}
     void setLongitude(float aLongitude){longitude = aLongitude;}
     double getLatitude(){return latitude;}
     double getLongitude(){return longitude;}
};

char buffer0[8];
char buffer1[8];
char buffer2[8];
char buffer3[8];
Coordinates allCoords[18];
int times,p;
bool path_saved = false;
int wp_cnt = 0;

long distance_sensor, distance_tmp;

int compassAdress = 0x21, slaveMicroControllerAddress = 2;
float current_latitude, current_longitude; 
int heading, calibrated_heading, desired_heading;
float distance_to_next_point;
//unsigned long time, tmp;

char buffer[17];
char *latEnd;
/*************************************************************************************************
 *                                    CONTROLLER'S SETUP                                         *
 *************************************************************************************************/
void setup()
{
  Wire.begin();          // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output
  pinMode(motor1a, OUTPUT);
  pinMode(motor1b, OUTPUT);
  pinMode(motor2a, OUTPUT);
  pinMode(motor2b, OUTPUT);
  pinMode(fix2DPin, INPUT);
}

The final code seems to stuck in one of the while loops where I wait to receive serial data from my computer’s serial COM port through the application. Its also unable to connect to the IDE serial port so I can’t figure out where it stucks exactly. Could those declarations affect the serial communication between the serial COM port of my PC and the arduino board? If not, why on earth the final code stucks? This is very odd

This is very odd

What Arduino is this code running on? I'm guessing that you are running out of memory.

Now, all that I add in the final code, are those declerations:

That is not all you did. You changed the size of the allCoords array, too.

Try removing chunks of the added code until it works again. Then re-add lines of code until you can pin down a single line that stops it working when you add it. Then either there is a bug in that line, or that line is causing you to run out of memory or some other resource.

ArduinoBT. My question is, how is the part code running and not the whole deal? If I was running out of memory, it shouldnt work at all. Thats why I'm asking about those declerations. Could any of those place something in arduino's buffer?

I'm wondering how your loop() gets by with a missing }--I suppose that can only be a typo in the post and not the actual code?

Joe

jmknapp:
I'm wondering how your loop() gets by with a missing }--I suppose that can only be a typo in the post and not the actual code?

Joe

yeh, thats a typo in the post.

If I was running out of memory, it shouldnt work at all.

It works until the stack gets corrupt because you ran out of memory.

Thats why I'm asking about those declerations. Could any of those place something in arduino's buffer?

Any? They all use memory.

dc42:
Try removing chunks of the added code until it works again. Then re-add lines of code until you can pin down a single line that stops it working when you add it. Then either there is a bug in that line, or that line is causing you to run out of memory or some other resource.

Jeez. It was a line of code that caused all this mess. I was saving the number of points, in a global variable right after the filling of buffer1. I moved it to the end of the function and it worked.

thank you all for your replies!