Skip to content
Permalink
Browse files

Handle holding the dc reference differently in GraphicsRenderer.Creat…

…eContext methods
  • Loading branch information...
Robin Dunn
Robin Dunn committed Aug 7, 2019
1 parent 7344be2 commit c9afb213188da1a7de8e715f9d655ac699c93097
Showing with 18 additions and 5 deletions.
  1. +18 −5 etg/graphics.py
@@ -208,11 +208,24 @@ def markCreateFactories(klass):
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()

0 comments on commit c9afb21

Please sign in to comment.
You can’t perform that action at this time.