Skip to content

Commit 32fd38a

Browse files
committed
Fix wxWidget crash caused by GDI id limit
1 parent 777ba69 commit 32fd38a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

gui/builtinShipBrowser/pfListPane.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def RemoveWidget(self, child):
163163
def RemoveAllChildren(self):
164164
for widget in self._wList:
165165
widget.Destroy()
166+
# 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
167+
for i in widget.__dict__.keys():
168+
widget.__dict__[i] =None
169+
del widget
166170

167171
self.Scroll(0, 0)
168172
self._wList = []

gui/utils/gdi.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import gc
2+
from ctypes import *
3+
from collections import defaultdict
4+
import os
5+
def gdiReport(desc=''):
6+
PH = windll.kernel32.OpenProcess(0x400, 0, os.getpid())
7+
numGdi = windll.user32.GetGuiResources(PH, 0)
8+
windll.kernel32.CloseHandle(PH)
9+
print (f'{desc}, {numGdi}')
10+
11+
12+
last = None
13+
def output_memory():
14+
global last
15+
d = defaultdict(int)
16+
for o in gc.get_objects():
17+
name = type(o).__name__
18+
if name == 'Bitmap':
19+
del o
20+
d[name] += 1
21+
22+
items = d.items()
23+
items = sorted(items,key=lambda x:x[1])
24+
print('------')
25+
for key, value in items:
26+
if last is not None:
27+
if value -last[key] !=0:
28+
print(f'{key} {value - last[key]}, {value}')
29+
else:
30+
print( key, value)
31+
32+
last = d

0 commit comments

Comments
 (0)