1 year ago

#82115

test-img

user456789

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt In Sharpdx

I have a Sharpdx Program and I'm trying to initialize a RenderTarget to draw on a RenderForm Here is my Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpDX;
using SharpDX.Direct2D1;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using AlphaMode = SharpDX.Direct2D1.AlphaMode;
using Factory = SharpDX.Direct2D1.Factory;
using FeatureLevel = SharpDX.Direct2D1.FeatureLevel;

namespace Proto_Engine
{
    class D2DX11
    {
        SharpDX.Direct3D11.Device _device;
        SwapChain _swapChain;
        public Factory Factory2D { get; private set; }
        public SharpDX.DirectWrite.Factory FactoryDWrite { get; private set; }
        public RenderTarget RenderTarget2D { get; private set; }
        private Surface _surface;
        public D2DX11() { }
        public void Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription =
                    new ModeDescription(configuration.Width,
                                        configuration.Height,
                                        new Rational(60, 1),
                                        Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = windowHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };
            SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain);

            Factory factory = _swapChain.GetParent<Factory>();

            // New RenderTargetView from the backbuffer

            Factory2D = new Factory();
            _surface = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0).QueryInterface<Surface>();
            RenderTarget2D = new RenderTarget(Factory2D,
                                                _surface,
                                                new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            RenderTarget2D.DrawRectangle(new SharpDX.Mathematics.Interop.RawRectangleF(0, 1, 1, 0), new SolidColorBrush(RenderTarget2D, new SharpDX.Mathematics.Interop.RawColor4(1, 0, 0, 1)));
        }
    }
}

This Is Causing the Issue

SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain);

I'm Getting This Error

Attempted To Read Or Write Protected Memory.  This Is Often An Indication That Other Memory Is Corrupt

I've been working on This for weeks but I Am mostly working On the 3d Aspect of it So I'm trying to implement 2D rendering to create UI. I'm getting the IntPtr windowhandle fro my Renderform and DSystemConfiguration is a custom class that I created

c#

sharpdx

0 Answers

Your Answer

Accepted video resources