GIGA R1 Interrupt Issue

As an undergraduate student, I am trying to use an incremental encoder to control a DC motor. I wrote the following code to receive the encoder value (it was the same even though it was originally unified as mbed code), but when an interrupt occurs and the operation is performed in the decode function, the GIGA's LED blinks red and does not work. I'm not sure what the cause is. help...

#include "motor.h"
#include "mbed.h"
#define R (0b011)
#define G (0b101)
#define B (0b110)
using namespace mbed;
BusOut myled(PI_12,PJ_13,PE_3);
BusIn phase(PA_3,PA_2);
void Red(){
  myled =R;
}
void Green(){
  myled = G;
}
void Blue(){
  myled =B;
}
uint8_t pre_phase;
int32_t count;
uint32_t error_count;

void decode(){
  volatile uint8_t new_phase=phase;
    switch((pre_phase<<2) | new_phase)
    {
    case 0b0001:
    case 0b0111:
    case 0b1110:
    case 0b1000:
        count--;
        break;
    case 0b0010:
    case 0b1011:
    case 0b1101:
    case 0b0100:
        count++;
        break;
    default:
        error_count++;
        break;
    }
    pre_phase=new_phase;
}

Encoder enco;

void setup() {
  // put your setup code here, to run once:
  Green();
  attachInterrupt(digitalPinToInterrupt(2),decode,CHANGE);
  attachInterrupt(digitalPinToInterrupt(3),decode,CHANGE);
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  
  Serial.begin(115200);
}


void loop() {
  // put your main code here, to run repeatedly:
  
  Serial.print(digitalRead(2),BIN);
  Serial.println(digitalRead(3),BIN);
  
  Serial.print("count: ");
  Serial.println(count);
  Serial.print("error: ");
  Serial.println(error_count());
  delay(1);
}

Any particular reason you are using "change". Sometimes better to choose "rising" or "falling" as Interrupt trigger. This generates less interrupt calls etc.

So, because you are using "change", you are probably triggering the interrupt function a stack of times before the routine is likely to have finished. As such, to ensure the routine completes and mitigate any potential problems, a good idea is to consider detaching the interrupt at the start of the ISR (i.e. decode function) and the reattach the interrupt as last line to initiate again. This way code always completes but it's at risk as of a missed event etc.

Then have another think about your global variables. How is the code changing these. If by interrupt and you are also checking the value of these variables in a loop function, would it be better to class these as volatile or not.

Thanks for your answer!
I solved the problem by deleting the Business object. But I don't know why it works.