Why would TMap and TArray cause crashes if declared non static?
I have a problem with TMaps. I don't have the code here but it should be very simple to explain.
I have a member of type TMap inside a class inherited from PlayerState. When I try to use this variable for adding an element I get a crash (I don't remember the call stack exactly but I remember it crashed after 2 calls to the Emplace function or immediately after). The same identical code works perfectly if I declare the TMap as static (I've been using it for a couple of weeks without crashes).
I thought it could have been something about the garbage collector, deleting elements inside the TMap (it seemed to be strange as the elements are of type FName and uint32 that shouldn't be garbage collected but I had no clue about other possibilities).
I tried to use a TArray of struct (the struct just had an FName and a uint32 as for the map) instead than a TMap and when trying to add an element to it I got the same crash! Again if declaring the TArray as static everything worked well. This has been just a test as I have to use a TMap.
So, I don't think the element inside these two structures are garbage collected, I think are the elements theirselves that are or maybe they don't keep the memory reserved, or something like that.
Do you have any suggestion about what I could investigate to understand where the problem can be?
Thank you for the answer. Today I have found the solution to my problem. For simplicity sake in the thread I wrote that the variable is in the PlayerState inherited class but in truth it is in a component, the PlayerState only keep a subobject pointer to it. The problem was that that pointer wasn't declared as UPROPERTY and the component object was invalidated after a while, not completely garbage collected anyway, so it was possible to call its functions but the map and array were causing crashes,
answered May 19 '14 at 06:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here