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"

Unmounting PAK does not close file

My game mounts pak files at runtime containing custom maps. Occasionally, these pak files may need to be re-downloaded while they are mounted. The issue I'm running into is that my steam workshop download fails to complete because the pak file is locked. I've tried simply unmounting the pak before download, but that does not seem to unlock the file; the download still fails and i cannot modify the file in file explorer until I close my game.

I've managed to work around this by copying pak files to a PakCache folder before mounting so that there's never any conflicts. This works, but has the potential to be pretty heavy on the hard drive.

My guess is that IPlatformFilePak is leaving a FileHandle open on mount and there's no way to close it. So far I've found this one:

 bool FPakPlatformFile::Mount(const TCHAR* InPakFilename, uint32 PakOrder, const TCHAR* InPath /*= NULL*/)
 {
     UE_LOG(LogPakFile, Verbose, TEXT("Mounting Pak: %s"), InPakFilename);
 
     bool bSuccess = false;
     TSharedPtr<IFileHandle> PakHandle = MakeShareable(LowerLevel->OpenRead(InPakFilename));
     if (PakHandle.IsValid())
     {
         ...
     }
     else
     {
         UE_LOG(LogPakFile, Warning, TEXT("Pak \"%s\" does not exist!"), InPakFilename);
     }
     return bSuccess;
 }

I do not see PakHandle being closed, but I tried doing something like delete PakHandle.Get() and it caused a crash at runtime.

Product Version: UE 4.16
Tags:
more ▼

asked Aug 04 '17 at 05:28 AM in Bug Reports

avatar image

SlimeQ
332 10 21 39

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

1 answer: sort voted first

Actually I am able to delete unmounted paks from my PakCache which indicates to me that this was a user error. There is an issue however with proper pak unmounting when paks are mounted the way most resources say to do it. This is the recommended solution for mounting pak files at runtime:

     IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
     FPakPlatformFile* PakPlatform = new FPakPlatformFile();
     PakPlatform->Initialize(&PlatformFile, TEXT(""));
     PakPlatform->InitializeNewAsyncIO();
     FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);
 
     if (PakPlatform->Mount(*PakFileName, 0, *MountPoint)) {
         UE_LOG(ProxyWarGameInstance, Log, TEXT("Successfully mounted %s at %s"), *PakFileName, *MountPoint);
     }

This works, however, when you go to unmount the pak it will not be registered because there's a new PakPlatform every time. It will be removed from the pak precacher but the file handle will never be deleted. In order for this to happen, I had to initialize the PakPlatform file in my GameInstance's Init function and keep a pointer to it in the game instance. Then I just use that pointer to mount/unmount everything.

 void UMyGameInstance::Init() {
     ...
     IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
     PakPlatform = new FPakPlatformFile();
     PakPlatform->Initialize(&PlatformFile, TEXT(""));
     PakPlatform->InitializeNewAsyncIO();
     FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);
     ...
 }

 void UMyGameInstance::MountPak(FString PakFileName, FString MountPoint) {
     if (PakPlatform->Mount(*PakFileName, 0, *MountPoint)) {
         UE_LOG(LogTemp, Log, TEXT("Successfully mounted %s at %s"), *PakFileName, *MountPoint);
 
     }
 }
 
 void UMyGameInstance::UnmountPak(FString PakFileName) {
     if (PakPlatform->Unmount(*PakFileName)) {
         UE_LOG(LogTemp, Log, TEXT("Successfully unmounted pak at %s"), *PakFileName);
     }
     else {
         UE_LOG(LogTemp, Warning, TEXT("failed to unmount pak at %s"), *PakFileName);
     }
 }
more ▼

answered Aug 04 '17 at 05:31 PM

avatar image

SlimeQ
332 10 21 39

(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