Skip to content

Instablity Crash on Vulkan App using DLL with TLS and On Exit #52

Open

Description

@CycloneRing

Hi @bb107, After 2 years I'm back :D

I am working on a complicated project in Godot game engine. My project require loading some dll from memory which uses TLS (from Godot SDK) I tried many manual mappers and only one that works properly is yours which is really impressive.

However, After using MemoryModulePP (Static Link, DLL) It causes a instability in Godot when it tries to initialize Vulkan, D3D12, Sound Engine etc. and Leads to a _debugbreak And also It causes crash on Exit.

I did try many things and spent 3 days on debugging But I couldn't find the root, All I know is this is caused by loading MemoryModulePP and I guess it's caused by the hooks, Note that this only happens after loading the dll with TLS. Without TLS it looks fine.

I prepared a fully pre-setup project for looking into the issue which can be downloaded here.

This project contains Godot 4.3 engine, pre-built Godot SDK and GDExtension that uses MemoryModulePP. However in this test project I couldn't reproduce the startup crash on vulkan but exit crash is happening which I believe it's connected to the same startup bug.

This is a very critical project for me and I will really appreciate it if you can help me diagnose the issue and fix it.

One important thing is the startup initialization crash always happens after calling to RtlFreeHeap and raised by RtlReportCriticalFaliure and it happens same on Vulkan, D3D12, XInput etc.

Startup issue only happens randomly sometimes it doesn't happen sometimes it does.

image

Also sometimes break will be on MemoryModulePP itself at this line.

Do you have any idea or lead to fix the issue?
Thanks

Update 2 :

I got some clue on what is happening, So I believe something going wrong with hooks and things done in MemoryModulePP initialization.

  • Linking statically against MemoryModulePP.lib = Startup Random Crash Happens
  • Linking dynamically against MemoryModulePP.dll = Startup Random Crash Happens
  • Linking dynamically against MemoryModulePP.dll As Delayed DLL = Stable Startup

So If I delay loading of MemoryModule.dll which happens when it is needed to be called from, Startup instability won't happen.

Activity

  1. bb107 commented on Sep 30, 2024

    @bb107
    Owner

    Hi, thanks for your feedback, I will find time to test and fix this issue.

  2. added 2 commits that reference this issue on Oct 2, 2024
  3. bb107 commented on Oct 7, 2024

    @bb107
    Owner

    Hi, I just created a fix for this issue and it works fine on my computer. Please check out the MmpTlsFixup branch to test.
    For the crash on exit, just add the following code to DllMain to perform the cleanup:

    if (fdwReason == DLL_PROCESS_DETACH) {
    	MmCleanup();
    }
  4. bb107 commented on Oct 7, 2024

    @bb107
    Owner

    In addition, you need to add the _HAS_AUTO_INITIALIZE macro definition to the client project that references MMPP if you need to call MmInitialize automatically.

  5. CycloneRing commented on Oct 12, 2024

    @CycloneRing
    Author

    @bb107 Thanks a lot, I will test and let you know.

  6. CycloneRing commented on Oct 31, 2024

    @CycloneRing
    Author

    @bb107 Hey! I tested MmpTlsFixup in my project and now it seems working just fine. Thank you for your dedication, You truly made the most reliable PE loader for Windows.

    Also it seems it fixed some parts of this issue #53
    However there is still a random crash on Mutex and it's very hard to reproduce. It doesn't happen if we comment out this line

    You can close this issue and mark it as fixed. I appreciate if you can look or guess the root of the follow up issue.

  7. CycloneRing commented on Oct 31, 2024

    @CycloneRing
    Author

    @bb107 New update, Now it crashes randomly in mid app
    image

  8. bb107 commented on Nov 7, 2024

    @bb107
    Owner

    Hi, could you provide an example to reproduce these problems?

  9. CycloneRing commented on Nov 8, 2024

    @CycloneRing
    Author

    Hi, could you provide an example to reproduce these problems?

    Hi @bb107, Unfortunately they happen rarely for instance, I am using my project for 3 days and it didn't happen again, My guess is it's all about threading and timing. I update the repo if I could find more consistent data to provide you.

  10. added 6 commits that reference this issue on May 12, 2025
  11. added 2 commits that reference this issue on May 25, 2025
  12. added 2 commits that reference this issue on Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions