mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-07 20:40:11 +01:00
Handle holding the dc reference differently in GraphicsRenderer.CreateContext methods
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user