Skip to content

Commit 780f05f

Browse files
committed
Credit system BP: fix crashes when unloading then reloading UE levels
IsValid was a first attempt at fixing these crashes which were witnessed only in Shipping mode, ie. with no way of exactly knowing what was going on. But IsValid itself was apparently using CesiumCreditSystemBP after its deletion, so I ended up adding the object to the GC's root set.
1 parent ab6aea7 commit 780f05f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: Source/CesiumRuntime/Private/CesiumCreditSystem.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,15 @@ ACesiumCreditSystem::GetDefaultCreditSystem(const UObject* WorldContextObject) {
9393
// loader object that retrieves the blueprint class in its constructor. We can
9494
// destroy the loader immediately once it's done since it will have already
9595
// set CesiumCreditSystemBP.
96-
if (!CesiumCreditSystemBP) {
96+
if (!IsValid(CesiumCreditSystemBP)) {
9797
UCesiumCreditSystemBPLoader* bpLoader =
9898
NewObject<UCesiumCreditSystemBPLoader>();
9999
CesiumCreditSystemBP = bpLoader->CesiumCreditSystemBP.LoadSynchronous();
100+
// Prevent the GC from destroying the object when unloading a level, as it will be reused
101+
// if one subsequently loads another level. This kind of static object should probably be
102+
// replaced by a "subsystem"
103+
// (https://dev.epicgames.com/documentation/en-us/unreal-engine/programming-subsystems-in-unreal-engine)
104+
CesiumCreditSystemBP->AddToRoot();
100105
bpLoader->ConditionalBeginDestroy();
101106
}
102107

0 commit comments

Comments
 (0)