Closed echolox closed 9 months ago
Thanks for the report.
I looked into this to understand what's going on. When registering a module with Live++, it scans the surrounding +-2GB memory range/virtual address space and reserves free pages. When loading and installing a patch for a module later on, these free pages are freed temporarily, and the OS is tricked into loading the patch DLL inside that range. Afterwards, the remaining pages are reserved again. This is required since patches need to be loaded in the +-2GB address range in order to patch relocations to existing symbols.
However, this means that OBS is unable to hook the DXGI functions. Similar to Live++, Detours needs to be able to allocate some space for the trampoline next to the original function. But since all pages surrounding that function are reserved, this allocation fails.
I guess you're using LPP_MODULES_OPTION_ALL_IMPORT_MODULES when enabling modules? If your application is a single executable, use LPP_MODULES_OPTION_NONE instead. This will leave all other DLLs alone and not reserve any pages surrounding them, which should make Detours/OBS work.
Thank you for looking into it. Your suggestion was on point!
I've now switched from using LPP_MODULES_OPTION_ALL_IMPORT_MODULES to enabling the modules I need individually (the main .exe and the .dll for the renderer) using LPP_MODULES_OPTION_NONE. OBS hooked into the DXGI functions successfully.
Thank you so much for the quick support and for this invaluable tool in general.
Scenario:
I'm developing a game that uses D3D11 and DXGI for rendering, the swap-chain etc. When trying to capture the application via Open Broadcaster Software (OBS) Studio (version 30.0.2) it is not possible to capture the application using the "Game Capture" source. Only a "Window Capture" or full "Display Capture" works.
This problem is not critical, since it's relatively trivial to disable Live++ when I intend to capture game footage, which I'd do on a release build anyway. But it has tripped me up for a while that "Game Capture" wasn't working. I spent a lot of time looking through the setup code for my renderer trying things out until I stumbled upon the debug output below and tried the application without Live++ running. Ultimately my worry was just that players of the game would eventually run into the same problem trying to capture the game using "Game Capture". I'm no longer worried about that now :)
I don't understand enough about the details to say whether Live++ or OBS is in a position to fix this issue, or whether it's just an inherent limitation related to Microsoft Detours that cannot be solved. So maybe it would be enough to add this in the Documentation or FAQ so it's easier to figure out for other people in the future.
Steps to reproduce:
For comparison, creating a "Window Capture" in the same way works.
Thankfully OBS prints to the debug output when it attempts to hook into an application. When it fails the output looks as follows:
When it works it looks like this:
Diving a little into the OBS source code the failure likely occurs in
dxgi-capture.cpp
in the functionhook_dxgi
: https://github.com/obsproject/obs-studio/blob/master/plugins/win-capture/graphics-hook/dxgi-capture.cppThat last
error
receives the value 8 which matches "0x00000008 - ERROR_NOT_ENOUGH_MEMORY" from this table: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d Details on DetourAttach: https://github.com/microsoft/Detours/wiki/DetourAttach