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"

Editor crashes on memcpy

Hi ! I am currently working on a volume rendering project.

By using the data from a custom format, I must dynamically generate a Volume Texture and then a material using a custom shader. Here is the code I use to generate my texture:

 void VolumeRenderingManager::createVolumeTexture(std::string name, int sx, int sy, int sz, unsigned char* data)
     _width = sx;
     _height = sy;
     _depth = sz;
     const unsigned long TotalSize = _width * _height * _depth * 4;
     // Creating package and resource
     std::string ManualName = "T_" + name + std::to_string(_id);
     FString PackageName = TEXT("/Game/GeneratedTextures/");
     FString TextureName = ManualName.c_str();
     PackageName += TextureName;
     UPackage* Package = CreatePackage(NULL, *PackageName);
     IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
     FString RelativePath = FPaths::ProjectContentDir();
     _volumeTexture = NewObject<UVolumeTexture>((UObject*)Package, FName(*TextureName), RF_Public | RF_Standalone | RF_MarkAsRootSet);
     _volumeTexture->AddToRoot(); // No garbage collection
     _volumeTexture->PlatformData = new FTexturePlatformData();
     _volumeTexture->PlatformData->SizeX = _width;
     _volumeTexture->PlatformData->SizeY = _height;
     _volumeTexture->PlatformData->NumSlices = _depth;
     _volumeTexture->PlatformData->PixelFormat = EPixelFormat::PF_B8G8R8A8;
     _volumeTexture->MipGenSettings = TMGS_NoMipmaps;
     _volumeTexture->SRGB = false;
     _volumeTexture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
     // Creating mip
     FTexture2DMipMap* Mip = new(_volumeTexture->PlatformData->Mips) FTexture2DMipMap();
     Mip->SizeX = _width;
     Mip->SizeY = _height;
     Mip->SizeZ = _depth;
     // Copying data
     void* MipData = Mip->BulkData.Realloc(TotalSize);
     FMemory::Memcpy(MipData, &data, TotalSize);
     _volumeTexture->MipGenSettings = TMGS_LeaveExistingMips;
     _volumeTexture->Source.Init(_width, _height, _depth, 1, ETextureSourceFormat::TSF_RGBA8, data);
     FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
     bool bSaved = UPackage::SavePackage(Package, _volumeTexture, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
     // Then generating the material

The problem is that when I execute the code, I get the following error:

 [2019.07.03-08.31.35:961][519]LogWindows: Error: === Critical error: ===
 [2019.07.03-08.31.35:961][519]LogWindows: Error: 
 [2019.07.03-08.31.35:961][519]LogWindows: Error: Fatal error!
 [2019.07.03-08.31.35:961][519]LogWindows: Error: 
 [2019.07.03-08.31.35:961][519]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xdf0d0000

And then the logs indicate that the crash happens at this line:


However, if I try to print a UE_LOG just before this line, it doesn't appear. Which strongly makes me think that the actual error comes from the Memcpy:

 FMemory::Memcpy(MipData, &data, TotalSize);

By testing, I found out that there is a problem with the dimensions of my texture. The file I work with most is 100x100x60, but I managed to execute the code without errors by passing 18x18x18 (or less, like 16x16x16) as parameters to my function and I have no idea why this works.

Any ideas ?

Product Version: UE 4.22
more ▼

asked Jul 03 '19 at 01:24 PM in Rendering

avatar image

36 3 3

avatar image superdreamgen Aug 06 '19 at 05:38 AM

Have you found a solution to this? I'm getting a crash on BulkData.Unlock() after trying to Memcpy to a UTexture2D.

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

1 answer: sort voted first

Yes, I was actually dereferencing my data pointer...

 FMemory::Memcpy(MipData, &data, TotalSize);
 FMemory::Memcpy(MipData, data, TotalSize);

After this, I still had some crashes... turns out you may need to delete the data at the end of your function:

 delete[] data;

Hope this helps.

more ▼

answered Aug 06 '19 at 08:51 AM

avatar image

36 3 3

avatar image superdreamgen Aug 09 '19 at 07:55 PM

Thank you! I will try this.

(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