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"

Editor crashes on startup if uninitialized UPROPERTY object pointer is used in USTRUCT

If inside a USTRUCT an object pointer is declared as a UPROPERTY like this:

 USTRUCT(BlueprintType)
 struct FCrashingStruct
 {
     GENERATED_USTRUCT_BODY()
 
 public:
     FCrashingStruct()
     {
     }
 
     UPROPERTY()
     AActor* Object;
 };

...the editor crashes on startup (assert fails) at the following location:

 UE4Editor-CoreUObject.dll!TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::ProcessObjectArray(TArray<UObject *,FDefaultAllocator> & InObjectsToSerializeArray, TRefCountPtr<FGraphEvent> & MyCompletionGraphEvent) Line 293    C++
  UE4Editor-CoreUObject.dll!TGraphTask<TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::FCollectorTask>::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 883    C++
  UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasks() Line 1277    C++
  UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasksUntilQuit(int QueueIndex) Line 1171    C++
  UE4Editor-Core.dll!FTaskThreadBase::Run() Line 643    C++
  UE4Editor-Core.dll!FRunnableThreadWin::Run() Line 76    C++
  UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() Line 25    C++
  [External Code]    

However, if either the UPROPERTY() is removed, or the pointer is initialized to nullptr inside the struct's constructor, like this:

 FCrashingStruct()
 {
     Object = nullptr;
 }

...the editor starts up.

The log states:

[2017.02.22-10.00.06:511][ 0]LogUObjectBase:Error: Object flags are invalid or either Class or Outer is misaligned

This error is probably related to UE-23056 where the developer notes say 'Improper struct initialization' (which isn't being terribly specific).

I see that not initializing the pointer probably IS an improper initialization, and I get that this probably cannot be caught at compile time. However, it is a very obscure error to me that took some time to track down. Maybe an improved runtime error could be implemented that somehow names the affected struct?

Product Version: UE 4.15
Tags:
more ▼

asked Feb 22 '17 at 10:19 AM in C++ Programming

avatar image

TaurusI76
77 4 6 11

avatar image SOuNDSNC Feb 23 '17 at 09:37 PM

+1, this has happened to me. Very happy to have found this post.

avatar image Tim C ♦♦ STAFF Feb 24 '17 at 04:00 PM

Hi TaurusI76,

I believe you are correct that this is related to UE-23056. I can look into the possibility of a feature request to make the error message a bit more helpful.

How are you referencing the struct, though? I made an Actor class and added that struct to the class' header file, but opening the project in the Editor did not result in a crash for me.

Tim

avatar image SOuNDSNC Feb 24 '17 at 04:03 PM

The editor crashes if you call the constructor without initializing the pointer.

 FCrashingStruct SomeCrashingStruct; //We created a struct but AActor* Object hasn't been initialized as a nullptr
 SomeMethodThatUsesFCrashingStructAsParam(SomeCrashingStruct);
avatar image TaurusI76 Feb 24 '17 at 04:07 PM

I added a UPROPERTY with this struct to the actor class. That started to crash the editor.

avatar image Tim C ♦♦ STAFF Feb 24 '17 at 07:35 PM

It still is not crashing for me. I am not sure what I am doing differently from you. This is what I have in my class' header file:

 USTRUCT(BlueprintType)
 struct FCrashingStruct
 {
     GENERATED_USTRUCT_BODY()
 
 public:
     FCrashingStruct()
     {
     }
 
     UPROPERTY()
     AActor* Object;
 };
 
 UCLASS()
 class TESTSTRUCT3_API AMyActor : public AActor
 {
     GENERATED_BODY()
     
 public:    
     AMyActor();
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = TestCat)
     FCrashingStruct TheStruct;
 };

This project opens fine, even if I make a Blueprint of the class and place it in the default level. I also tried creating another local instance of the struct in my class' constructor, and that didn't result in a crash either.

avatar image SOuNDSNC Feb 24 '17 at 07:41 PM

You're not trying to do anything with it. Try passing it as a function parameter. Try broadcasting a delegate with the struct as a parameter. The crash at least for me was on the c++ level, I did nothing in blueprints at that point.

avatar image Tim C ♦♦ STAFF Feb 24 '17 at 08:31 PM

You're right, I had to actually touch the struct. Passing it into a function wasn't enough. I'll have to see if there is anything we can do to clarify what is happening here.

Tim

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hi everyone,

I was digging into this some more today, and noticed that the error message that I was getting does already somewhat hint at where the problem lies. This is the error that I am receiving: LogWindows:Error: Invalid object in GC: 0x000007fec7bda848, ReferencingObject: MyActor /Script/TestStruct3.Default__MyActor, ReferencingObjectClass: Class /Script/TestStruct3.MyActor, Property Name: Object, Offset: 1072, TokenIndex: 17

In this case, "Object" may not be the best name for the pointer in the struct. However, the error does indicate that there is a problem with the property named Object. Do you think that needs to be further clarified in this case?

Tim

more ▼

answered Mar 01 '17 at 08:32 PM

avatar image

Tim C ♦♦ STAFF
18.2k 423 69 286

avatar image TaurusI76 Mar 03 '17 at 11:56 AM

You're right, I missed that error message. My mistake was that when you stop the MS Visual Studio debugger at the point where it hits the breakpoint (and not click 'Continue' (twice), the UED doesn't finish the log so that line never gets written. I think the error message you posted is sufficient.

avatar image lpalbou May 12 '17 at 05:03 PM

I do confirm I have had twice that error (different projects). It is still unclear exactly why, but it is indeed related to pointers inside a FStruct. In my case not a AActor* but a UStaticMesh*:

     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties")
         UStaticMesh* MeshInSpace;

This pointer is not setup at structure creation, but is later setup after an ActorItem is created, containing this FStruct.

So I am guessing either: - there is a problem with the structure creation with UE4 engine (memory allocation ?) or - the engine somehow is trying to access a value to that pointer (some kind of reflexive analysis ?)

[EDIT] Strangely, just explicitly setting the variable inside the FStruct to nullptr was sufficient to remove the error & crash...

avatar image bstone Jun 16 '17 at 03:34 PM

Bumped into the same issue. A UPROPERTY() with a pointer to an actor declared inside USTRUCT() not being initialized when the struct is allocated on the stack. UE 4.16

avatar image Skylonxe Dec 11 '18 at 12:25 PM

I bumped into same issue in 4.20 too (Invalid object in GC). Unitialized UPROPERTY() UObject* in struct which is in struct (all of them marked as UPROPERTY) is causing crash on GC.

I created the struct in begin play with FMyStruct s = FMyStruct(); and then assigned to class variable of same type: StructClassVariable = s;

Actor class which contains StructClassVariable is placed in level and command obj gc is causing crash.

So what can be hapenning is that FMyStruct created as local variable does not have its variable initialized because it is not UPROPERTY() class variable and this variable is then assigned to class variable marked as UPROPERTY(). Next GC iterates over references and actor reference in class variable is not initialized, so it crashes.

(comments are locked)
10|2000 characters needed characters left
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