Description

In UCookOnTheFlyServer::BeginPackageCacheForCookedPlatformData(), there is a pointer to int32 called CurrentAsyncCache that is used as an index. It's value is dereferenced before it is checked, but it is not dereferenced when it is modified.

Not sure what the correct behavior is supposed to be, but looks like a potential mistake.

bool UCookOnTheFlyServer::BeginPackageCacheForCookedPlatformData(UPackage* Package, const TArray<const ITargetPlatform*>& TargetPlatforms, FCookerTimer& Timer) const
{
	COOK_STAT(FScopedDurationTimer DurationTimer(DetailedCookStats::TickCookOnTheSideBeginPackageCacheForCookedPlatformDataTimeSec));

#if DEBUG_COOKONTHEFLY 
	UE_LOG(LogCook, Display, TEXT("Caching objects for package %s"), *Package->GetFName().ToString());
#endif
	MakePackageFullyLoaded(Package);
	FReentryData& CurrentReentryData = GetReentryData(Package);

	if (CurrentReentryData.bIsValid == false)
		return true;

	if (CurrentReentryData.bBeginCacheFinished)
		return true;

	for (; CurrentReentryData.BeginCacheCount < CurrentReentryData.CachedObjectsInOuter.Num(); ++CurrentReentryData.BeginCacheCount)
	{
		UObject* Obj = CurrentReentryData.CachedObjectsInOuter[CurrentReentryData.BeginCacheCount];
		for (const ITargetPlatform* TargetPlatform : TargetPlatforms)
		{
			const FName ClassFName = Obj->GetClass()->GetFName();
			int32* CurrentAsyncCache = CurrentAsyncCacheForType.Find(ClassFName);
			if ( CurrentAsyncCache != nullptr )
			{
				if ( *CurrentAsyncCache <= 0 )
				{
					return false;
				}

				int32* Value = CurrentReentryData.BeginCacheCallCount.Find(ClassFName);
				if ( !Value )
				{
					CurrentReentryData.BeginCacheCallCount.Add(ClassFName,1);
				}
				else
				{
					*Value += 1;
				}
				CurrentAsyncCache -= 1;
			}

			if (Obj->IsA(UMaterialInterface::StaticClass()))
			{
				if (GShaderCompilingManager->GetNumRemainingJobs() > MaxConcurrentShaderJobs)
				{
#if DEBUG_COOKONTHEFLY
					UE_LOG(LogCook, Display, TEXT("Delaying shader compilation of material %s"), *Obj->GetFullName());
#endif
					return false;
				}
			}
			Obj->BeginCacheForCookedPlatformData(TargetPlatform);
		}

		if (Timer.IsTimeUp())
		{
#if DEBUG_COOKONTHEFLY
			UE_LOG(LogCook, Display, TEXT("Object %s took too long to cache"), *Obj->GetFullName());
#endif
			return false;
		}
	}

	CurrentReentryData.bBeginCacheFinished = true;
	return true;

}
Steps to Reproduce

Unclear, but confirmed typo with DanL.

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-53332 in the post.

0
Login to Vote

Fixed
ComponentUE - Foundation - Core - Cooker
Affects Versions4.18.24.19
Target Fix4.19
Fix Commit3806215
Main Commit3806215
Release Commit3813083
CreatedDec 12, 2017
ResolvedDec 13, 2017
UpdatedApr 27, 2018