Add ComPtr<T>.Release to simplify native objects
このコミットが含まれているのは:
1 親
3b31b9abe2
コミット
4ec0b1e43e
6ファイル変更
+22
-40
検索条件に一致するファイルはありません
+1
-4
@@ -305,10 +305,7 @@ partial struct PixelShaderEffect
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
// Free the previous ID2D1DrawInfo object, if present
|
||||
if (@this->d2D1DrawInfo is not null)
|
||||
{
|
||||
_ = @this->d2D1DrawInfo->Release();
|
||||
}
|
||||
ComPtr<ID2D1DrawInfo>.Release(@this->d2D1DrawInfo);
|
||||
|
||||
// Store the new ID2D1DrawInfo object
|
||||
_ = drawInfo->AddRef();
|
||||
|
||||
+1
-4
@@ -116,10 +116,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
// Free the previous ID2D1EffectContext object, if present
|
||||
if (@this->d2D1EffectContext is not null)
|
||||
{
|
||||
_ = @this->d2D1EffectContext->Release();
|
||||
}
|
||||
ComPtr<ID2D1EffectContext>.Release(@this->d2D1EffectContext);
|
||||
|
||||
// Store the new ID2D1EffectContext object
|
||||
_ = effectContext->AddRef();
|
||||
|
||||
@@ -263,10 +263,7 @@ unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
// If there's already an existing manager, release it
|
||||
if (@this->d2D1TransformMapper is not null)
|
||||
{
|
||||
_ = ((IUnknown*)@this->d2D1TransformMapper)->Release();
|
||||
}
|
||||
ComPtr<ID2D1TransformMapper>.Release(@this->d2D1TransformMapper);
|
||||
|
||||
// Store the transform mapper manager into the effect
|
||||
@this->d2D1TransformMapper = transformMapper.Detach();
|
||||
@@ -389,10 +386,7 @@ unsafe partial struct PixelShaderEffect
|
||||
ref ID2D1ResourceTextureManager* currentResourceTextureManager = ref this.resourceTextureManagerBuffer[index];
|
||||
|
||||
// If there's already an existing manager at this index, release it
|
||||
if (currentResourceTextureManager is not null)
|
||||
{
|
||||
_ = ((IUnknown*)currentResourceTextureManager)->Release();
|
||||
}
|
||||
ComPtr<ID2D1ResourceTextureManager>.Release(currentResourceTextureManager);
|
||||
|
||||
// Store the resource texture manager into the buffer
|
||||
currentResourceTextureManager = resourceTextureManager.Detach();
|
||||
|
||||
@@ -243,30 +243,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
NativeMemory.Free(this.constantBuffer);
|
||||
|
||||
if (this.d2D1TransformMapper is not null)
|
||||
{
|
||||
_ = ((IUnknown*)this.d2D1TransformMapper)->Release();
|
||||
}
|
||||
|
||||
if (this.d2D1DrawInfo is not null)
|
||||
{
|
||||
_ = this.d2D1DrawInfo->Release();
|
||||
}
|
||||
|
||||
if (this.d2D1EffectContext is not null)
|
||||
{
|
||||
_ = this.d2D1EffectContext->Release();
|
||||
}
|
||||
ComPtr<ID2D1TransformMapper>.Release(this.d2D1TransformMapper);
|
||||
ComPtr<ID2D1DrawInfo>.Release(this.d2D1DrawInfo);
|
||||
ComPtr<ID2D1EffectContext>.Release(this.d2D1EffectContext);
|
||||
|
||||
// Retrieve all possible resource texture managers in use and release the ones that had been assigned (from one of the property bindings)
|
||||
for (int i = 0; i < resourceTextureDescriptionCount; i++)
|
||||
{
|
||||
ID2D1ResourceTextureManager* resourceTextureManager = this.resourceTextureManagerBuffer[i];
|
||||
|
||||
if (resourceTextureManager is not null)
|
||||
{
|
||||
_ = ((IUnknown*)resourceTextureManager)->Release();
|
||||
}
|
||||
ComPtr<ID2D1ResourceTextureManager>.Release(this.resourceTextureManagerBuffer[i]);
|
||||
}
|
||||
|
||||
NativeMemory.Free(Unsafe.AsPointer(ref this));
|
||||
|
||||
+1
-4
@@ -247,10 +247,7 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
this.d2D1Multithread->Enter();
|
||||
|
||||
// Release the resource too if it has been created
|
||||
if (this.d2D1ResourceTexture is not null)
|
||||
{
|
||||
_ = this.d2D1ResourceTexture->Release();
|
||||
}
|
||||
ComPtr<ID2D1ResourceTexture>.Release(this.d2D1ResourceTexture);
|
||||
|
||||
// Now that the resource, if any, has been released, the effect context can also
|
||||
// be released. This must be done only after any associated resource textures have
|
||||
|
||||
@@ -38,6 +38,19 @@ internal unsafe struct ComPtr<T> : IDisposable
|
||||
InternalAddRef();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases a target COM object, if it's not <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">The COM object to potentially release.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Release(T* other)
|
||||
{
|
||||
if (other is not null)
|
||||
{
|
||||
_ = ((IUnknown*)other)->Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Converts a raw pointer to a new <see cref="ComPtr{T}"/> instance and increments the ref count.</summary>
|
||||
/// <param name="other">The raw pointer to wrap.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする