[CoreGraphics] Fix lifetime of delegates passed to CGPatternCreate. (#6356)

We may get callbacks after the managed CGPattern instance has been
disposed/garbage collected, so make sure our delegates survives that long.

Since the delegates don't need any instance state, just make them static.
This commit is contained in:
Rolf Bjarne Kvinge 2019-06-19 07:04:58 +02:00 коммит произвёл GitHub
Родитель 4992af65b6
Коммит 7b63ee42ff
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -79,7 +79,11 @@ namespace CoreGraphics {
/* CGFloat */ nfloat xStep, /* CGFloat */ nfloat yStep, CGPatternTiling tiling, bool isColored,
/* const CGPatternCallbacks* */ ref CGPatternCallbacks callbacks);
CGPatternCallbacks callbacks;
static CGPatternCallbacks callbacks = new CGPatternCallbacks () {
version = 0,
draw = DrawCallback,
release = ReleaseCallback,
};
GCHandle gch;
public CGPattern (CGRect bounds, CGAffineTransform matrix, nfloat xStep, nfloat yStep, CGPatternTiling tiling, bool isColored, DrawPattern drawPattern)
@ -87,10 +91,6 @@ namespace CoreGraphics {
if (drawPattern == null)
throw new ArgumentNullException (nameof (drawPattern));
callbacks.draw = DrawCallback;
callbacks.release = ReleaseCallback;
callbacks.version = 0;
gch = GCHandle.Alloc (drawPattern);
Handle = CGPatternCreate (GCHandle.ToIntPtr (gch), bounds, matrix, xStep, yStep, tiling, isColored, ref callbacks);
}