Skip to content

Memory allocation exception in Unreal editor during crash handling screenshot capture #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nwhite-riot opened this issue May 5, 2025 · 5 comments · May be fixed by #900
Open

Memory allocation exception in Unreal editor during crash handling screenshot capture #895

nwhite-riot opened this issue May 5, 2025 · 5 comments · May be fixed by #900
Labels
Bug Something isn't working

Comments

@nwhite-riot
Copy link
Collaborator

It seems like a crash in the editor that attempts to capture a screenshot will cause a memory allocation exception/secondary crash to occur due to screenshot being generated.

[Inline Frame] UnrealEditor-Core.dll!_mi_page_malloc(mi_heap_s *) Line 33	C
UnrealEditor-Core.dll!_mi_malloc_generic(mi_heap_s * heap, unsigned __int64 size) Line 875	C
UnrealEditor-Core.dll!_mi_heap_malloc_zero(mi_heap_s * heap, unsigned __int64 size, bool zero) Line 148	C
UnrealEditor-Core.dll!mi_heap_malloc_zero_aligned_at(mi_heap_s * const heap, const unsigned __int64 size, const unsigned __int64 alignment, const unsigned __int64 offset, const bool zero) Line 47	C
[Inline Frame] UnrealEditor-Core.dll!mi_heap_malloc_aligned_at(mi_heap_s *) Line 66	C
[Inline Frame] UnrealEditor-Core.dll!mi_heap_malloc_aligned(mi_heap_s *) Line 70	C
UnrealEditor-Core.dll!mi_malloc_aligned(unsigned __int64 size, unsigned __int64 alignment) Line 97	C
[Inline Frame] UnrealEditor-Core.dll!FMallocMimalloc::TryMalloc(unsigned __int64 Alignment, unsigned int) Line 83	C++
UnrealEditor-Core.dll!FMallocMimalloc::Malloc(unsigned __int64 Size, unsigned int Alignment) Line 90	C++
[Inline Frame] UnrealEditor-Core.dll!FLowLevelMemTracker::IsEnabled() Line 1086	C++
UnrealEditor-Core.dll!FMemory::Malloc(unsigned __int64 Count, unsigned int Alignment) Line 27	C++
UnrealEditor-ImageWrapper.dll!png_malloc(png_struct_def * png_ptr, unsigned __int64 size) Line 503	C
UnrealEditor-ImageWrapper.dll!png_zalloc(void * png_ptr, unsigned int items, unsigned int size) Line 92	C
UnrealEditor-ImageWrapper.dll!deflateInit2_()	C
UnrealEditor-ImageWrapper.dll!png_write_IHDR(png_struct_def * png_ptr, unsigned int width, unsigned int height, int bit_depth, int color_type, int compression_type, int filter_type, int interlace_type) Line 659	C
UnrealEditor-ImageWrapper.dll!png_write_info_before_PLTE(png_struct_def * png_ptr, png_info_def * info_ptr) Line 62	C
UnrealEditor-ImageWrapper.dll!png_write_info(png_struct_def * png_ptr, png_info_def * info_ptr) Line 133	C
UnrealEditor-ImageWrapper.dll!png_write_png(png_struct_def * png_ptr, png_info_def * info_ptr, int transforms, void * params) Line 1534	C
UnrealEditor-ImageWrapper.dll!FPngImageWrapper::Compress(int Quality) Line 257	C++
UnrealEditor-ImageWrapper.dll!FImageWrapperBase::GetCompressed(int Quality) Line 49	C++
UnrealEditor-ImageWrapper.dll!FImageWrapperModule::CompressImage(TArray<unsigned char,TSizedDefaultAllocator<64>> & OutData, EImageFormat ToFormat, const FImageView & InImage, int Quality) Line 478	C++
[Inline Frame] UnrealEditor-Engine.dll!FImageUtils::CompressImage(TArray<unsigned char,TSizedDefaultAllocator<64>> &) Line 156	C++
UnrealEditor-Engine.dll!FImageUtils::PNGCompressImageArray(int ImageWidth, int ImageHeight, const TArrayView<FColor const ,__int64> & SrcData, TArray<unsigned char,TSizedDefaultAllocator<64>> & DstData) Line 1032	C++
UnrealEditor-Sentry.dll!SentryScreenshotUtils::CaptureScreenshot(const FString & ScreenshotSavePath) Line 67	C++
UnrealEditor-Sentry.dll!FGenericPlatformSentrySubsystem::TryCaptureScreenshot() Line 581	C++
UnrealEditor-Sentry.dll!FGenericPlatformSentrySubsystem::OnCrash(const sentry_ucontext_s * uctx, sentry_value_u event, void * closure) Line 127	C++
UnrealEditor-Sentry.dll!FWindowsSentrySubsystem::OnCrash(const sentry_ucontext_s * uctx, sentry_value_u event, void * closure) Line 53	C++
UnrealEditor-Sentry.dll!FGenericPlatformSentrySubsystem::HandleOnCrash(const sentry_ucontext_s * uctx, sentry_value_u event, void * closure) Line 84	C++
UnrealEditor-Sentry.dll!sentry__backend_new()	Unknown
UnrealEditor-Sentry.dll!crashpad::CrashpadClient::StartHandler(class base::FilePath const &,class base::FilePath const &,class base::FilePath const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char	Unknown
@nwhite-riot nwhite-riot added the Bug Something isn't working label May 5, 2025
@nwhite-riot nwhite-riot changed the title Memory allocation exception in Unreal editor during crash handling Memory allocation exception in Unreal editor during crash handling screenshot capture May 5, 2025
@nwhite-riot
Copy link
Collaborator Author

I expect we should allocate memory for the image buffer at startup so we're not trying to allocate during a crash

@tustanivsky
Copy link
Collaborator

Do you have any additional information about the screen resolution, etc. on the machine where this behavior occurs? I wasn’t able to reproduce it on a 4K screen and am just trying to understand the constraints on memory allocation during crash handling

@nwhite-riot
Copy link
Collaborator Author

I don't think it's 100% repro, but I was running Development Editor Win64 and this crash occurred when running PIE in a new window. The window was relatively small - something like 1280 x 720.

@nwhite-riot
Copy link
Collaborator Author

nwhite-riot commented May 6, 2025

am just trying to understand the constraints on memory allocation during crash handling

In general, we should avoid any memory allocations during crash handling

@tustanivsky
Copy link
Collaborator

Alright, based on our previous findings (#410) the solution here could be simply moving image buffers to heap instead allocating them on stack.

Basically, whenever the crash handler gets called a special stack for it is allocated in the heap. This allows crash handler to operate even when the crashing game ran out of stack space.

The problem with this approach is that if the image buffer for screenshot is allocated on stack within the stack of a crash handler it can easily overflow it and overwrite some heap variables which may eventually lead to another crash.

@nwhite-riot Can you please give it another shot with the change suggested in #900?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants