[CoreAnimation] Ensure that we increase the handle refenrece count in MakeMutable. Fixes #3089 (#3099)

* [CoreAnimation] Ensure that we increate the handle referene in MakeMutable. Fixes 3089

Fixes https://github.com/xamarin/xamarin-macios/issues/3089
This commit is contained in:
Manuel de la Pena 2017-12-15 16:13:42 +01:00 коммит произвёл GitHub
Родитель 53f260166d
Коммит cb688be5c4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 22 добавлений и 3 удалений

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

@ -560,9 +560,7 @@ namespace XamCore.CoreGraphics {
static CGPath MakeMutable (IntPtr source)
{
var mutable = CGPathCreateMutableCopy (source);
CGPathRelease (source);
return new CGPath (mutable, true);
return new CGPath (mutable, false);
}
[DllImport (Constants.CoreGraphicsLibrary)]

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

@ -9,6 +9,7 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
#if XAMCORE_2_0
using Foundation;
using CoreGraphics;
@ -16,6 +17,7 @@ using CoreGraphics;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
#endif
using ObjCRuntime;
using NUnit.Framework;
#if XAMCORE_2_0
@ -34,6 +36,9 @@ namespace MonoTouchFixtures.CoreGraphics {
[Preserve (AllMembers = true)]
public class PathTest {
[DllImport (Constants.CoreFoundationLibrary)]
extern static nint CFGetRetainCount (IntPtr handle);
[Test]
public void EllipseFromRect ()
{
@ -259,5 +264,21 @@ namespace MonoTouchFixtures.CoreGraphics {
Assert.IsNotNull (path, "path");
}
}
[Test]
public void IncreaseRetainCountMakeMutable ()
{
// ensure that we do not crash and that the retain count is changed.
using (CGPath p1 = new CGPath ())
{
var count = CFGetRetainCount (p1.Handle);
using (var copy = p1.Copy ())
{
var newRetainCount = CFGetRetainCount (copy.Handle);
Assert.AreNotEqual (count, newRetainCount, $"Count is {newRetainCount} and was {count}");
Assert.IsTrue (count < newRetainCount);
}
}
}
}
}