I kid you not, I spent a full working day debugging this exact same issue (taking a pointer to a vector element, before adding more elements).
Very obvious if you understand how C++ and vectors work, yet it took me forever to realize, and it was miserable…