Skip to content

Commit

Permalink
Merge pull request #2629 from cryonox/dev/issue2121
Browse files Browse the repository at this point in the history
Fix wxWidget crash caused by GDI object limit
  • Loading branch information
DarkFenX authored Dec 5, 2024
2 parents 59847c3 + 32fd38a commit 0f4b082
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gui/builtinShipBrowser/pfListPane.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def RemoveWidget(self, child):
def RemoveAllChildren(self):
for widget in self._wList:
widget.Destroy()
# this forces the garbage collector to work properly by removing dangling references to objects which are still alive, otherwise widget cannot be gc-ed eventually causing GDI id exhaustion and crash
for i in widget.__dict__.keys():
widget.__dict__[i] =None
del widget

self.Scroll(0, 0)
self._wList = []
32 changes: 32 additions & 0 deletions gui/utils/gdi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import gc
from ctypes import *
from collections import defaultdict
import os
def gdiReport(desc=''):
PH = windll.kernel32.OpenProcess(0x400, 0, os.getpid())
numGdi = windll.user32.GetGuiResources(PH, 0)
windll.kernel32.CloseHandle(PH)
print (f'{desc}, {numGdi}')


last = None
def output_memory():
global last
d = defaultdict(int)
for o in gc.get_objects():
name = type(o).__name__
if name == 'Bitmap':
del o
d[name] += 1

items = d.items()
items = sorted(items,key=lambda x:x[1])
print('------')
for key, value in items:
if last is not None:
if value -last[key] !=0:
print(f'{key} {value - last[key]}, {value}')
else:
print( key, value)

last = d

0 comments on commit 0f4b082

Please sign in to comment.