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

Commit

Permalink
The SharpDX commit b9f7519 causes the .NET Native compiler to crash.
Browse files Browse the repository at this point in the history
This change works around the .NET Native bug by casting to (IntPtr).

I also noticed that DataBuffer had the same issue as DataStream which was
fixed by b9f7519 so I applied the same fix to DataBuffer.

FWIW the code in question calls Interop.Fixed which throws
NotImplementedException.
  • Loading branch information
Joe Erickson authored and Joe Erickson committed Oct 19, 2016
1 parent 7d0dcb9 commit e520e10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Source/SharpDX/DataBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ public static DataBuffer Create<T>(T[] userBuffer, int index = 0, bool pinBuffer
DataBuffer buffer;

var sizeOfBuffer = Utilities.SizeOf(userBuffer);
var indexOffset = index * Utilities.SizeOf<T>();

if (pinBuffer)
{
var handle = GCHandle.Alloc(userBuffer, GCHandleType.Pinned);
var indexOffset = index * Utilities.SizeOf<T>();
buffer = new DataBuffer(indexOffset + (byte*)handle.AddrOfPinnedObject(), sizeOfBuffer - indexOffset, handle);
}
else
{
buffer = new DataBuffer(Interop.Fixed(userBuffer), sizeOfBuffer, true);
// The .NET Native compiler crashes if '(IntPtr)' is removed.
buffer = new DataBuffer(indexOffset + (byte *)(IntPtr)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, true);
}

return buffer;
Expand Down
3 changes: 2 additions & 1 deletion Source/SharpDX/DataStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public static DataStream Create<T>(T[] userBuffer, bool canRead, bool canWrite,
}
else
{
stream = new DataStream(indexOffset + (byte*)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, canRead, canWrite, true);
// The .NET Native compiler crashes if '(IntPtr)' is removed.
stream = new DataStream(indexOffset + (byte*)(IntPtr)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, canRead, canWrite, true);
}

return stream;
Expand Down

0 comments on commit e520e10

Please sign in to comment.