Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Direct3d11 small fix and improvement #1132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Source/SharpDX.Direct3D11/DeviceContext.ComputeShaderStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,16 @@ public unsafe void SetUnorderedAccessViews(int startSlot, SharpDX.Direct3D11.Uno
fixed (void* puav = uavInitialCounts)
SetUnorderedAccessViews(startSlot, unorderedAccessViews != null ? unorderedAccessViews.Length : 0, (IntPtr)unorderedAccessViewsOut_, (IntPtr)puav);
}

/// <summary>
/// Sets an array of views for an unordered resource.
/// </summary>
/// <param name="startSlot">Index of the first element in the zero-based array to begin setting. </param>
/// <param name="unorderedAccessViews">A reference to an array of <see cref="SharpDX.Direct3D11.UnorderedAccessView"/> references to be set by the method. </param>
public unsafe void SetUnorderedAccessViews(int startSlot, ComArray<SharpDX.Direct3D11.UnorderedAccessView> unorderedAccessViews, int[] uavInitialCounts)
{
fixed (void* puav = uavInitialCounts)
SetUnorderedAccessViews(startSlot, unorderedAccessViews == null ? 0 : unorderedAccessViews.Length, unorderedAccessViews.NativePointer, (IntPtr)puav);
Copy link

@h1cks h1cks Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't you get a null pointer exception on unorderedAccessViews.NativePointer for SetUnorderedAccessViews as you are not testing the 3rd parameter that the object is also Null? You would need to repeat the same test on the 3rd parameter also, so that you do not get a null reference exception if the object is null when calling NativePointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thinking of that in pretty much all existing DeviceContext "Set[]" which use ComArray, there is no null check at all, so could actually remove the first check.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of such cases, agreed, but I think if you did check Null Pointer on unorderedAccessViews then that woudl be fine. OR for removing ambiguity, set the code as:

fixed (void* puav = uavInitialCounts) { if (unorderedAccessViews != null) { SetUnorderedAccessViews(startSlot, unorderedAccessViews.Length, uorderedAccessViews.NativePointer, (IntPtr)puav); } else { SetUnorderedAccessViews(startSlot, 0, null, (IntPtr)puav); } }

I think the null pointer checks are correct that you are doing. I think some expansion to protect against a legitimate use case where the UAV is set to null. But yes, there are some checks missed in the code.

}
}
}
3 changes: 2 additions & 1 deletion Source/SharpDX.Direct3D11/DeviceContext.OutputMergerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public UnorderedAccessView[] GetUnorderedAccessViews(int startSlot, int count)
var temp = new UnorderedAccessView[count];
DepthStencilView depthStencilView;
GetRenderTargetsAndUnorderedAccessViews(0, new RenderTargetView[0], out depthStencilView, startSlot, count, temp);
depthStencilView.Dispose();
if (depthStencilView != null)
depthStencilView.Dispose();
return temp;
}

Expand Down