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"

[BUG] FWindowsPlatformMemory fails if statements in MapnamedSharedMemoryRegion()

I'm trying to use FGenericPlatformMemory's Shared Memory code so I can publish some game data using Shared Memory. I have to use Shared Memory because it's a requirement. It would be very convenient for me if I could just use Unreal Engine's shared memory stuff.

The problem is in the FWindowsPlatformMemory::MapNamedSharedMemoryRegion() function. There is a block of if-statements that never get executed no matter what you pass into the function.

It's almost as if the if statements are being compiled out. It's causing my code to fail, and I get this in the Unreal Editor Log:

 LogHAL:Warning: CreateFileMapping(file=INVALID_HANDLE_VALUE, security=NULL, protect=0x4, MaxSizeHigh=0, MaxSizeLow=262168, name='Global\UnrealEngineVideoCapture') failed with GetLastError() = 5

The GetLastError()=5 corresponds to Windows System Error code of ERROR_ACCESS_DENIED.

I literally step through my code using breakpoints in Visual Studio and I can see the debugger stepping passed the if statement when it was supposed to go into the if statement block on line 181 of WindowsPlatformMemory.cpp

It's logically equivalent to this little example:

 myfunc(4)
 
 void myfunc(int x)
 {
     if(x == 4)
     {
      print hello
     }
 }

and your program never prints hello.

It's completely bizarre, so that's why I believe those if statements are getting compiled out.

This is how I'm creating the Shared Memory region:

         bool create = true;
 
         SharedMemoryRegion =
             FPlatformMemory::MapNamedSharedMemoryRegion(
             TEXT("UnrealEngineVideoCapture"),
             create,
             FPlatformMemory::ESharedMemoryAccess::Write | FPlatformMemory::ESharedMemoryAccess::Read,
             GetRenderTargetSize() + SHARED_MEMORY_HEADER_SIZE);

This is the file I am talking about and these are the if statements:

in WindowsPlatformMemory.cpp lines 174-182 and lines 189-196:

 FPlatformMemory::FSharedMemoryRegion* FWindowsPlatformMemory::MapNamedSharedMemoryRegion(const FString& InName, bool bCreate, uint32 AccessMode, SIZE_T Size)
 {
     FString Name(TEXT("Global\\"));
     Name += InName;
 
     DWORD OpenMappingAccess = FILE_MAP_READ;
     check(AccessMode != 0);

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////           THIS IF-ELSE BLOCK GETS SKIPPED
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     if (AccessMode == FPlatformMemory::ESharedMemoryAccess::Write)
     {
         OpenMappingAccess = FILE_MAP_WRITE;
     }
     else if (AccessMode == (FPlatformMemory::ESharedMemoryAccess::Write | FPlatformMemory::ESharedMemoryAccess::Read))
     {
         OpenMappingAccess = FILE_MAP_ALL_ACCESS;
     }

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////          END
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     HANDLE Mapping = NULL;
     if (bCreate)
     {
         DWORD CreateMappingAccess = PAGE_READONLY;
         check(AccessMode != 0);

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////           THIS IF-ELSE BLOCK ALSO GETS SKIPPED
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

         if (AccessMode == FPlatformMemory::ESharedMemoryAccess::Write)
         {
             CreateMappingAccess = PAGE_WRITECOPY;
         }
         else if (AccessMode == (FPlatformMemory::ESharedMemoryAccess::Write | FPlatformMemory::ESharedMemoryAccess::Read))
         {
             CreateMappingAccess = PAGE_READWRITE;
         }

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////           END
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ///................... SOME MORE CODE HERE........................

     return new FWindowsSharedMemoryRegion(Name, AccessMode, Ptr, Size, Mapping);
 }


Has anyone else had this problem? How did you resolve it? Is there any way to disable some of the compiler flags when I build my project?

Thanks

Product Version: UE 4.7
Tags:
more ▼

asked May 15 '15 at 08:35 PM in C++ Programming

avatar image

jgcoded
21 4 8 10

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

0 answers: sort voted first
Be the first one to answer this question
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