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

Commit e520e10

Browse files
Joe EricksonJoe Erickson
authored andcommitted
The SharpDX commit b9f7519 causes the .NET Native compiler to crash.
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.
1 parent 7d0dcb9 commit e520e10

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Source/SharpDX/DataBuffer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ public static DataBuffer Create<T>(T[] userBuffer, int index = 0, bool pinBuffer
5959
DataBuffer buffer;
6060

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

6364
if (pinBuffer)
6465
{
6566
var handle = GCHandle.Alloc(userBuffer, GCHandleType.Pinned);
66-
var indexOffset = index * Utilities.SizeOf<T>();
6767
buffer = new DataBuffer(indexOffset + (byte*)handle.AddrOfPinnedObject(), sizeOfBuffer - indexOffset, handle);
6868
}
6969
else
7070
{
71-
buffer = new DataBuffer(Interop.Fixed(userBuffer), sizeOfBuffer, true);
71+
// The .NET Native compiler crashes if '(IntPtr)' is removed.
72+
buffer = new DataBuffer(indexOffset + (byte *)(IntPtr)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, true);
7273
}
7374

7475
return buffer;

Source/SharpDX/DataStream.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public static DataStream Create<T>(T[] userBuffer, bool canRead, bool canWrite,
115115
}
116116
else
117117
{
118-
stream = new DataStream(indexOffset + (byte*)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, canRead, canWrite, true);
118+
// The .NET Native compiler crashes if '(IntPtr)' is removed.
119+
stream = new DataStream(indexOffset + (byte*)(IntPtr)Interop.Fixed(userBuffer), sizeOfBuffer - indexOffset, canRead, canWrite, true);
119120
}
120121

121122
return stream;

0 commit comments

Comments
 (0)