Skip to content
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

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

Open
CycloneRing opened this issue Sep 30, 2024 · 8 comments
Open

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

CycloneRing opened this issue Sep 30, 2024 · 8 comments

Comments

@CycloneRing
Copy link

CycloneRing commented Sep 30, 2024

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.

@bb107
Copy link
Owner

bb107 commented Sep 30, 2024

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

@bb107
Copy link
Owner

bb107 commented Oct 7, 2024

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();
}

@bb107
Copy link
Owner

bb107 commented Oct 7, 2024

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.

@CycloneRing
Copy link
Author

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

@CycloneRing
Copy link
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.

@CycloneRing
Copy link
Author

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

@bb107
Copy link
Owner

bb107 commented Nov 7, 2024

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

@CycloneRing
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants