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

[NBug] An unexpected internal error occurred in the Win32 call: 80... #9429

Open
luweeewu opened this issue Jul 29, 2021 · 30 comments · Fixed by #9566
Open

[NBug] An unexpected internal error occurred in the Win32 call: 80... #9429

luweeewu opened this issue Jul 29, 2021 · 30 comments · Fixed by #9566

Comments

@luweeewu
Copy link

luweeewu commented Jul 29, 2021

Current behaviour

Program crashed sometime during the night.

Expected behaviour

Shouldn't crash.

Steps to reproduce

Leave the program running overnight.

Error Details

System.ComponentModel.Win32Exception: An unexpected internal error occurred in the Win32 call: 8007007E ---> System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

   --- End of inner exception stack trace ---
   at Microsoft.WindowsAPICodePack.Dialogs.NativeTaskDialog.NativeShow()
   at Microsoft.WindowsAPICodePack.Dialogs.TaskDialog.ShowCore()
   at GitUI.NBugReports.BugReportInvoker.Report(Exception exception, Boolean isTerminating)
   at GitExtensions.Program.<>c.<Main>b__1_3(Object s, ThreadExceptionEventArgs e)
   at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Additional information

Left the program running overnight.

Environment

  • Git Extensions 3.5.1.12196
  • Build 9099a1e
  • Git 2.31.1.windows.1
  • Microsoft Windows NT 6.2.9200.0
  • .NET Framework 4.8.4390.0
  • DPI 96dpi (no scaling)
@duplicates-detector-bot

This comment has been minimized.

1 similar comment
@duplicates-detector-bot
Copy link

Potential duplicates:

  • #9381
  • #9394

@mstv
Copy link
Member

mstv commented Aug 2, 2021

Was a Windows update being installed or a reboot pending?

@luweeewu
Copy link
Author

luweeewu commented Aug 3, 2021 via email

@mstv
Copy link
Member

mstv commented Aug 3, 2021

@luweeewu, @Kableado, @dallf44,

could you enable the exception log files (refer to #9166 (comment)) and share them after the next crash, please?

@dallf44
Copy link

dallf44 commented Aug 3, 2021

It did not happen again, but I'll try.

@luweeewu
Copy link
Author

luweeewu commented Aug 6, 2021 via email

@mstv
Copy link
Member

mstv commented Aug 6, 2021

Here are the log files as you requested.

GH removes mail attachments. Could you paste them here?

@luweeewu
Copy link
Author

luweeewu commented Aug 6, 2021

GH removes mail attachments. Could you paste them here?

GitExtensions.3.5.1.12196.20210806.034820042.log
GitExtensions.3.5.1.12196.20210806.034820344.log

@mstv
Copy link
Member

mstv commented Aug 6, 2021

One detail to note: When I have my view set to Show all branches, I can leave Git Extensions open for days, and it won’t crash. The crashes seem to happen if I have the view set to Show current branch only.

Thank you. This will help to track down the issue.
In a short test, I did not notice a leak of GDI objects. But according to the exception, the GDI pool might be exhausted (usually 10000 or 20000).
Does the number of GDI objects used by GE increase significantly over the time? (TaskManager | Details | Add column "GDI objects")

System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
   at System.Windows.Forms.ToolStripProfessionalRenderer.OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
   at System.Windows.Forms.ToolStripRenderer.DrawItemImage(ToolStripItemImageRenderEventArgs e)
   at System.Windows.Forms.ToolStripButton.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.ToolStripItem.HandlePaint(PaintEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at GitUI.ToolStripEx.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

@luweeewu
Copy link
Author

luweeewu commented Aug 7, 2021 via email

@RussKie
Copy link
Member

RussKie commented Aug 7, 2021

Are you running the dark theme?

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Aug 7, 2021
@mstv
Copy link
Member

mstv commented Aug 7, 2021

The number of GDI objects increases on refresh in dark theme also with Show all branches and without Left Panel, Build Server Integration, Avatars, Toolbars.

@mstv mstv added status: reproducible and removed 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity labels Aug 7, 2021
@luweeewu
Copy link
Author

luweeewu commented Aug 9, 2021 via email

@luweeewu
Copy link
Author

luweeewu commented Aug 9, 2021 via email

@mstv
Copy link
Member

mstv commented Aug 10, 2021

The number of GDI objects increases on refresh in dark theme also with Show all branches and without Left Panel, Build Server Integration, Avatars, Toolbars.

@NikolayXHD, it seems to be caused by a core functionality. Could you have a look?

@NikolayXHD
Copy link
Member

@NikolayXHD, it seems to be caused by a core functionality. Could you have a look?

ok, the coming weekend

@luweeewu
Copy link
Author

I noticed that the number of GDI objects increases when showing all branches in dark mode, but nowhere near as catastrophically as when showing only the current branch. After a couple of days, the number of GDI objects is sitting at just over a couple hundred when showing all branches vs several thousand after a day when showing only the current branch.

@luweeewu
Copy link
Author

I just had a look at the GDI object count now, and it was up over 59k. This was with leaving it set to show all branches for the entire time since I left a comment yesterday morning.

@pmiossec
Copy link
Member

pmiossec commented Aug 30, 2021

I did a quick investigation using GDIVew on the portable version of v3.5.3

With default theme:

Total GDIs objects Font Brush bitmap Palette Region DC Action
149 35 10 18 1 6 21 Startup & open repo
156 43 10 18 1 6 21 After refresh
151 38 10 18 1 6 21 After refresh
156 43 10 18 1 6 21 After refresh
152 40 10 18 1 6 21 After refresh
155 43 10 18 1 6 21 After refresh
156 44 10 18 1 6 21 After refresh
155 43 10 18 1 6 21 After refresh
151 39 10 18 1 6 21 After scrolling
156 44 10 18 1 6 21 After 10 refresh
151 39 10 18 1 6 21 After 10 refresh
161 41 10 18 1 6 21 After switch repositories

With dark theme:

Total GDIs objects Font Brush bitmap Palette Region DC Action
153 25 24 16 1 4 19 Startup
194 33 42 18 1 7 21 Open repo
216 42 56 18 1 7 21 after refresh
231 42 71 18 1 7 21 after refresh
236 36 82 18 1 7 21 after refresh
355 42 195 18 1 7 21 After 10 refresh

From these numbers, we could clearly see that dark theme is leaking brushes.... Approximately 10 by refresh.

/cc @NikolayXHD

@pmiossec
Copy link
Member

pmiossec commented Aug 30, 2021

We could have the 'Handle ref' and the 'kernel address' but I don't know if it could help debugging in VS:

image

Edit (from GDIView doc):

Kernel Address: The memory address in Windows Kernel that contains the data structure of this handle. Regular Windows application cannot read from this address, only device drivers can access it. However, you can view the content this memory by using WinDbg in kernel debugging mode.

@pmiossec
Copy link
Member

Spotted maybe another GDI leak:

The brushes count increase regularly when scrolling (by 8 or 10 at each page scrolled approximately)
When hiding the revision graph column, the number nearly stopped to increase (but still a small increase of 1 or 2 some time to time after a big scroll) .

Hiding the revision graph when doing a refresh doesn't reduce a lot the the brushes increase so it's possible that we have to main leaks...

@pmiossec
Copy link
Member

After a little last test, hypothesis that should be verified:

Even if hidden, the revision graph is calculated for the commits actually displayed when doing a refresh and so is the same reason why there is a brush leak when doing a refresh.

@pmiossec
Copy link
Member

Another one I think:
With only the revision grid visible (left panel, commit info and diff panel hidden, revision graph hidden), when you change the selected revision you leak every time some brushes: 1 or 3 most of the time (in rare cases it could be 5)

Not a clear pattern but it seems to be most of the times 1 brush is leaked when you select a commit from the same author and 3 when from another author (but not always because in rare cases you leak also 3 for the same author). I struggle to know if the option "highlight commits from same author has an impact"...

I spent also some time trying to debug the application but without success. If someone has an idea and could have a look now that we know that we leak only brushes with none 'default' theme...

@RussKie
Copy link
Member

RussKie commented Aug 30, 2021 via email

@RussKie
Copy link
Member

RussKie commented Aug 30, 2021 via email

@pmiossec
Copy link
Member

Were you able to narrow what method result in leaks?

No. I spent most of the time trying to find a pattern that could give me a clue on the piece of code to investigate.

One way of trying to find these is by commenting out code.

Yes it is a good idea but l didn't want to comment half of GE code 😅

I only spent 30min trying to debug the application (especially revision graph code) but without success.

And I don't know when I will be able to give it another try....

@RussKie
Copy link
Member

RussKie commented Aug 31, 2021 via email

@NikolayXHD
Copy link
Member

So, I can see the hard work is done - undoubtedly gdi objects are leaking.

When rendering code needs a brush, the one it gets may be a system brush, or a customized newly created brush adjusted for theme settings.

Because of that, the code which uses such brushes is not allowed to dispose them - system brushes are not supposed to be disposed.

What I plan to do, is return a Disposable brush wrapper, which knows whether the underlying actual brush should be disposed or not. All the brush consuming code will unconditionally call Dispose() on the wrapper.

Fill free to object :)

@ghost ghost added the 🚧 status: in progress Issues which have associated PRs label Sep 11, 2021
@gerhardol
Copy link
Member

Please test the portable build in #9566 (currently latest build is https://ci.appveyor.com/project/gitextensions/gitextensions/builds/40747903/artifacts, there may be updates though).
This fixes an issue seen with themes as seen here, if you also could check the GDI object count it would be great.

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

Successfully merging a pull request may close this issue.

7 participants