Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
more ▼

asked May 17 '14 at 11:13 AM in C++ Programming

avatar image

18 2 4 7

avatar image gmpreussner STAFF May 19 '14 at 03:14 PM

Hi Ivan, this doesn't make any sense, and no, trivial types are not garbage collected - only UObject based types are. Can you post the code for your class declaration, as well as the code that uses it and crashes?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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,

more ▼

answered May 19 '14 at 06:54 PM

avatar image

18 2 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question