You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just opened some of my old MG code and have been working on updating them from NET Framework 4.8 to .NET 6.0/7.0. Most of my old projects went smooth to update, but I have run into some trouble on a project that was using my Oculus headset.
My old code was based on a for long forgotten project, but I found som identical code on https://github.com/demonixis/C3DE
To get the Occulus headset working, there is a need to access the native textures for two render targets, This was done before with this code;
public static IntPtr GetNativeDxResource(this RenderTarget2D renderTarget2D)
{
var renderTarget2DType = typeof(RenderTarget2D);
var textureInfo = renderTarget2DType.GetField("_texture", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var resourceObj = textureInfo.GetValue(renderTarget2D);
var resourceType = resourceObj.GetType();
var resourcePtrInfo = resourceType.GetProperty("NativePointer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
return (IntPtr)resourcePtrInfo.GetValue(resourceObj);
}
After the upgrade this code created an exception, since the "_texture" was not found
But in the latest update (3.8.1.303) I found that this code could be simplified with;
public static IntPtr GetNativeDxResource(this RenderTarget2D renderTarget2D)
{
var handle = renderTarget2D.GetSharedHandle();
return handle;
}
Unfortunately the procedure was only returning IntPtr.Zero
To fix this, I changed the creation of the two render targets, forcing it to use shared memory
var renderTarget = new RenderTarget2D(graphicsDevice, res.X, res.Y, false, surfaceFormat, depthFormat, 0, RenderTargetUsage.DiscardContents, shared: true);
Now I finally got the handle to the textures and hoped everything should work. But as soon as I submitted them to Oculus (via the same DLL I used a couple of years ago) I run into my latest problem
public int SubmitRenderTargets(RenderTarget2D rtLeft, RenderTarget2D rtRight, int frame = 0)
{
IntPtr dxTexLeft = rtLeft.GetNativeDxResource();
IntPtr dxTexRight = rtRight.GetNativeDxResource();
return NativeRift.SubmitRenderTargets(dxTexLeft, dxTexRight, frame);
}
The error: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I must have missed something but can not figure it out. Any help is welcome
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've just opened some of my old MG code and have been working on updating them from NET Framework 4.8 to .NET 6.0/7.0. Most of my old projects went smooth to update, but I have run into some trouble on a project that was using my Oculus headset.
My old code was based on a for long forgotten project, but I found som identical code on https://github.com/demonixis/C3DE
To get the Occulus headset working, there is a need to access the native textures for two render targets, This was done before with this code;
After the upgrade this code created an exception, since the "_texture" was not found
But in the latest update (3.8.1.303) I found that this code could be simplified with;
Unfortunately the procedure was only returning IntPtr.Zero
To fix this, I changed the creation of the two render targets, forcing it to use shared memory
Now I finally got the handle to the textures and hoped everything should work. But as soon as I submitted them to Oculus (via the same DLL I used a couple of years ago) I run into my latest problem
The error: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I must have missed something but can not figure it out. Any help is welcome
Kind regards
Robert
Beta Was this translation helpful? Give feedback.
All reactions