Handle holding the dc reference differently in GraphicsRenderer.CreateContext methods

This commit is contained in:
Robin Dunn
2019-08-07 12:32:18 -07:00
committed by Robin Dunn
parent 8efd6385a1
commit 6b5adab03f

View File

@@ -208,11 +208,24 @@ def run():
markCreateFactories(c)
c.abstract = True
for m in c.find('CreateContext').all():
for p in m.items:
if 'DC' in p.name or p.name == 'image':
p.keepReference = True
c.find('CreateContextFromImage.image').keepReference = True
# The KeepReference annotation doesn't work for us in this case, as it will
# hold the reference in the renderer object, but it is better to hold the
# reference in the returned context object instead. Otherwise there is still
# some possibility that the held DC will be destroyed before the context.
c.addPyCode("""\
def _ctx_hold_ref(f):
from functools import wraps
@wraps(f)
def wrapper(self, obj):
ctx = f(self, obj)
ctx._obj = obj
return ctx
return wrapper
GraphicsRenderer.CreateContext = _ctx_hold_ref(GraphicsRenderer.CreateContext)
GraphicsRenderer.CreateContextFromImage = _ctx_hold_ref(GraphicsRenderer.CreateContextFromImage)
GraphicsRenderer.CreateContextFromUnknownDC = _ctx_hold_ref(GraphicsRenderer.CreateContextFromUnknownDC)
""")
# TODO: support this?
c.find('CreateContext').findOverload('wxEnhMetaFileDC').ignore()