Skip to content
Browse files

Handle holding the dc reference differently in GraphicsRenderer.Creat…

…eContext methods
  • Loading branch information...
Robin Dunn authored and RobinD42 committed Aug 7, 2019
1 parent 8efd638 commit 6b5adab03fd45bc4350d98ce9dbb3f3573a43bac
Showing with 18 additions and 5 deletions.
  1. +18 −5 etg/
@@ -208,11 +208,24 @@ def markCreateFactories(klass):
c.abstract = True

for m in c.find('CreateContext').all():
for p in m.items:
if 'DC' in or == '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.
def _ctx_hold_ref(f):
from functools import wraps
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?

0 comments on commit 6b5adab

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