justinstenning / Direct3DHook

DirectX Capture and Overlays by using Direct3D API hooks
http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks
MIT License
580 stars 178 forks source link

Attempt to update image element every frame in d3d11? #65

Closed jazzup closed 1 year ago

jazzup commented 6 years ago

In Form1.cs, I added: new Capture.Hook.Common.ImageElement(){Location = new System.Drawing.Point(0, 50)} to the list of Elements.

In DXImage.cs, I added to public bool Initialise(System.Drawing.Bitmap bitmap): bitmap = new Bitmap(@"E:\texture.png");

This will display texture.png on top of game.

I next rigged an external program to update (overwrite) texture.png (on E: drive) at the rate of one texture every second. The updated texture.png does not display unless I do away with _imagecache which then causes a memory leak. I am also disposing of bitmap right after the Unlock: bitmap.UnlockBits(bmData);

Any suggestions?

jazzup commented 6 years ago

Thank you for taking the time.

Memory leak still occurs and only when texture is updated on top of game. If I display the texture without updating it, then it's ok.

I checked Memory leak in ImageElement #45 https://github.com/spazzarama/Direct3DHook/issues/45, does it seem like possible solution?

On Sat, Jun 9, 2018 at 4:14 AM, Justin Stenning notifications@github.com wrote:

You will need to dispose the bitmap before loading the new one.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spazzarama/Direct3DHook/issues/65#issuecomment-395928801, or mute the thread https://github.com/notifications/unsubscribe-auth/ANTLG09i5Ux5eFAd8xOpb6bFYhPhy19jks5t6yFngaJpZM4UgZFs .

justinstenning commented 6 years ago

@jazzup it might be easier to reset the overlay via the IPC interface each second: see btnDisplayOverlay_Click in the TestScreenshot project.

jazzup commented 6 years ago

@spazzarama I replied to your post a few days ago using my email client, but I don't see it here. Sorry.

I found out that the external program which updates the texture stops updating because the file is open in another process.

Strangely, this very same setup works flawlessly in the old version of DXHookD3D9, before switching to overlay engine. I also used texconv.exe to convert each new texture to .DDS with virtually no impact on the fps.

That's why I thought to extend this option to d3d11 never realizing this issue could happen. I apologize for wasting your time. This was really a question and not an issue. Great project by the way!

justinstenning commented 1 year ago

I believe this fixes the memory leak: https://github.com/justinstenning/Direct3DHook/commit/601bc6d778b4a2c84a78633666b7785da9e605ec