x

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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Exception when calling method, Object is valid

I am currently writing a Replication Graph for my Master's thesis.

During the GatherActorListsForConnection calls, it crashes when calling the method for my custom ReplicationGraphNode (UReplicationGraphNode_Room).

Code:

 for (auto RoomMapEntry : Rooms) {
     if (RoomMapEntry.Key == nullptr) {
         UE_LOG(LogTemp, Error, TEXT("Room is null"));
         continue;
     }
     if (InsideRoom(RoomMapEntry.Key->GetRoomInfo(), Params.Viewer.ViewLocation)) {
         if (IsValid(RoomMapEntry.Key) && IsValid(RoomMapEntry.Key->GetDynamicNode())
         && &RoomMapEntry.Key != nullptr) {
             //Call fails, RoomMapEntry.Key-> is 0x0
             RoomMapEntry.Key->GatherActorListsForConnection(Params);
         }
     }
 }

Rooms is a TMap: TMap<UReplicationGraphNode_Room*, TArray<UReplicationGraphNode_Room*>> Rooms;

The function call fails with the message RoomMapEntry.Key-> was 0x0 (or 0xFFFFFCF), even though I test for objects that could be null. I create the Key entries as follows:

 UReplicationGraphNode_Room* NewRoom = NewObject<UReplicationGraphNode_Room>();
         NewRoom->SetRoomInfo(FRoomInfo(Tuple.Key, Tuple.Value));

I don't know what to search for, I cannot debug any further, the GatherActorListsForConnection function is never reached. I also specifically implemented the function, turned off pragma optimization and debugged with the DebugGame-Editor, still the same error. Why am I getting this exception even though I test for the object being null?

Product Version: UE 4.21
Tags:
more ▼

asked May 14 '19 at 03:30 PM in C++ Programming

avatar image

izzy278
1 1 2

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

2 answers: sort voted first

SOLVED: I now fixed the issue by changing the Map to a TArray of a struct containing the information and declaring that as a UPROPERTY().

Apparently nested containers (TArray in TMap) cannot be done (Error only appeared after declaring it a UPROPERTY) and maybe declaring it a UPROPERTY() got rid of memory/garbage collection issues...

more ▼

answered May 15 '19 at 09:40 AM

avatar image

izzy278
1 1 2

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

it's indeed strange it passing 0x0 only way to explain it is that key get nulled after the check, but if you get 0xFFFFFCF that means it's invalid pointer, and it will pass null check as it's different value then null which in most cases is value 0. If thats the case your code will crash at RoomMapEntry.Key->GetRoomInfo() in if condition check right after.

Also in you use IsValid there no point of making null pointer check as IsValid does null check already, also by doing`&RoomMapEntry.Key` you creating pointer of a statically declared pointer variable which never will be null. So your code can be reduced to this:

  for (auto RoomMapEntry : Rooms) {
      if (IsValid(RoomMapEntry.Key)) {
          UE_LOG(LogTemp, Error, TEXT("Room is null or invalid"));
          continue;
      }
      if (InsideRoom(RoomMapEntry.Key->GetRoomInfo(), Params.Viewer.ViewLocation)) {
          if (IsValid(RoomMapEntry.Key->GetDynamicNode())) {
              RoomMapEntry.Key->GatherActorListsForConnection(Params);
          }
      }
  }

Now reason why you may have invalid pointers is usally UE4 not seeing the object reference in property or engine not seeing property at all and GC deletes the object as it see it as trash. It's either missing UPROPERTY() on TMap or container you using don't raport object reference (Which if i remember right it might be the case with TMap). Or you manually deleted it and if TMap indeed don't cooperate with GC it will have invalid pointer

I'm also not sure about TArray in TMap as for example TArray in TArray is not supported.

Also make sure to check the logs as they might tell you more about crash, check Saved/Logs in your project directory.

more ▼

answered May 14 '19 at 11:18 PM

avatar image

Shadowriver
36.5k 930 169 1111

avatar image izzy278 May 15 '19 at 09:41 AM

I think you are right with the Map needing the UPROPERTY() macro and the nested containers.

I created a Top level answer describing how I fixed it.

(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