Garbage Collection Error :: 'this' pointer is invalid

I got this error after 30 sec starting the game . Could anyone help me? Thanks a lot …

[2015.09.02-12.51.36:387][821]LogUObjectBase:Error: ‘this’ pointer is invalid.
[2015.09.02-12.51.36:389][821]LogWindows:Error: Windows GetLastError: The operation completed successfully. (0)
[2015.09.02-12.51.37:023][821]LogWindows:Warning: CreateProc failed (2) …....\Engine\Binaries/Win64/CrashReportClient.exe -AppName=UE4-MyApp
[2015.09.02-12.51.37:024][821]LogWindows: Could not start CrashReportClient.exe
[2015.09.02-12.51.37:024][821]LogMemory: Platform Memory Stats for WindowsServer
[2015.09.02-12.51.37:025][821]LogMemory: Process Physical Memory: 113.55 MB used, 113.66 MB peak
[2015.09.02-12.51.37:025][821]LogMemory: Process Virtual Memory: 170.93 MB used, 184.88 MB peak
[2015.09.02-12.51.37:025][821]LogMemory: Physical Memory: 5197.61 MB used, 32644.16 MB total
[2015.09.02-12.51.37:026][821]LogMemory: Virtual Memory: 428.64 MB used, 134217728.00 MB total
[2015.09.02-12.51.43:478][821]LogWindows: === Critical error: ===
Fatal error: [File:D:\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp] [Line: 383]
Invalid object in GC: 0x0000000000000003, ReferencingObject: TryingCharacter_C /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.TryingCharacter_C_0, ReferencingObjectClass: BlueprintGeneratedClass /Game/MyApp/Characters/TryingCharacter.TryingCharacter_C, Property Name: Item, Offset: 8, TokenIndex: 42

link text

“this” can be invalid when object is removed from memory during exec his code. To prevent object to be garbage collected hold it in variable with UPROPERTY() macro, so it will be visible in reflection system that it’s referenced somewhere and in use.

In case of that object is not refrenced anywhere and you want it to stay alive set RootSet flag to class ( Something->SetFlags(RF_RootSet); ), but keep in mind if you set that flag garbage collection won’t collect it, so you need to take care of removing it if needed (if you create only one for entire time, you don’t need to, when you close process whole it memory will be freed)

1 Like

This character is a main character of players. So all player will play one copy of this and when disconnecting this object have to be deleted. If I add this flag when 1 player disconnecting, server will crash :cry:

where should I go and what should I do to actually prevent object to be GCed? I read many articles but they just explain stuff not telling how to do!

The reference to the object has to have a UPROPERTY() annotatiom above it to prevent it being garbage collected

I work with blueprints so I guess that’s why I couldn’t find any solution. But any way to do it with blueprints?!

Could it be that you are trying to get access to a disconnected players avatar in this case somewhere on the server?

Adding a isValid check before accessing their character could maybe save you from this crash.

You could also check if they are pending destroy too just to be safe