Terminating a function without being in its scope

I am currently starting to write code for a 12^3 RGB LED-Cube.
My question is about terminating a function within another function, I think this makes it clear:

class A
{
  public:
  A() {}

  void f()
  {
    while(1) {

    }
  }
  
};

A * a = new A();

void ISrR()
{
  //should somehow terminate f()
}

void setup() {
 pinMode(2, INPUT_PULLUP);
 attachInterrupt(digitalPinToInterrupt(2), ISrR, FALLING);
}

void loop() {
  a->f();
}

The real code is far more complex but this is the basic situation.
I already thought of periodically checking in blink() for a flag generated by the ISR but I would like to avoid that.
I know that I am doing something a bit wrong when I need to do something like this but:
f() / the class represents an animation and this function is blocking. My problem would be solved if I wrote it non blocking but trust me, you really do not want to write animations for a 12^3 RGB LED-Cube non-blocking. It makes some animations almost impossible / very ugly to write.

I hope somebody has an idea.
Thanks in Advance

ISrR could set false the flag that is currently a constant in the while loop.

But I suspect you should be rewriting your code.