Assigning a value to FText to an array element

I have an array of FText objects that I want to change the contents of at a later time, as such:

 TArray<FText> messages;
 void setMessage(uint8_t msgIndex, const FText& newMsg) {
     messages[msgIndex] = newMsg;

This compiles fine, but as soon as this line gets run the game crashes with an ‘Access violation reading location 0xFFFFFFFFFFFFFFFF’ error on the line ‘TOps::ReleaseSharedReference(ReferenceController)’ in the Shared Reference file.

What is the proper way to write this line?

Are you sure it’s not the TArray assignment that’s the problem? How big is the array when you assign into index msgIndex ?
If you build in debug mode, the RangeCheck() in TArray will tell you if you got the index wrong.
Also, which object is it trying to release? How do you create the FText in the first place? Do you create it with LOCTEXT() or what?

Thanks for this line, I debugged it slowly this time and it turns out the TextData inside messages[msgIndex] was null. Everything else was fine (the index exists, the array is big enough, etc.), but I had init the array using messages.AddUninitialized(numMessages). Changed it to AddDefaulted and things are fine now. Thanks!