I think it may be luck that your code works.

This statement stores the address of ptr1, which is somewhere on the stack.

ptrActive = &ptr1;

I've changed the pointers a bit and this at least...