Sketch freezing when sending command to motor

Hello, so I’m making an RC Car and the communication between the two boards(using VirtualWire) is happening perfectly, but I’m having a problem: Since I implemented the motor code (I’m using a motor shield) using the AFMotor library, the first time I send a command to the motors, the sketch freezes, nothing more happens and the motors stay in the state they were before the sketch got frozen.

Here’s the code:

#include <AFMotor.h>
#include <VirtualWire.h>

AF_DCMotor m1(1);
AF_DCMotor m2(2);
AF_DCMotor m3(3);
AF_DCMotor m4(4);

int state = 0;

void setup()
{
    Serial.begin(9600);	// Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_set_rx_pin(46);
    vw_setup(2000);	 // Bits per sec
    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
	int i;

        digitalWrite(13, true); // Flash a light to show received good message
	// Message with a good checksum received, dump it.
	Serial.print("Got: ");
	
	for (i = 0; i < buflen; i++)
	{
	    Serial.print(buf[i]);
	    Serial.print(" ");
	}
	Serial.println("");

  switch(buf[0]){
    case 'i':
    if(state != 0){
      mRelease();
      state = 0;
    }
      break;

    case 'f':
    if(state != 1){
      mForward();
      state = 1;
    }
      break;

    case 'b':
    if(state != 2){
      mBackward();
      state = 2;
    }
      break;

    case 'r':
    if(state != 3){
      mRight();
      state = 3;
    }
      break;

    case 'l':
    if(state != 4){
      mLeft();
      state = 4;
    }
      break;

  }
  
    }
}

void mRelease(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(RELEASE);
  m2.run(RELEASE);
  m3.run(RELEASE);
  m4.run(RELEASE);
  return;
 }

 void mForward(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(FORWARD);
  m2.run(FORWARD);
  m3.run(FORWARD);
  m4.run(FORWARD);

  return;
 }

 void mBackward(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(BACKWARD);
  m2.run(BACKWARD);
  m3.run(BACKWARD);
  m4.run(BACKWARD);

  return;
 }

 void mLeft(){
  m1.setSpeed(255);
  m2.setSpeed(200);
  m3.setSpeed(200);
  m4.setSpeed(255);
  
  m1.run(FORWARD);
  m2.run(BACKWARD);
  m3.run(BACKWARD);
  m4.run(FORWARD);

  return;
  }

 void mRight(){
  m1.setSpeed(200);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(200);
  
  m1.run(BACKWARD);
  m2.run(FORWARD);
  m3.run(FORWARD);
  m4.run(BACKWARD);

  return;
  }

Thanks in advance.

How are you powering your motor? Tell us exactly what motor too, that's vital information we aren't able to guess.

Motors need a capable supply and a separate supply from the Arduino 5V (motor supplies can see all sorts of nasty spikes and drop-outs that are bad news for logic chips).