I have an indcator that I've been working on for a while. My prior post was asking how to create a LinearGradientBrush to which I got the info for. Now I'm trying to implement it OnRender and I'm getting an error message saying "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
This is the code I'm running:
private LinearGradientBrush linGrBrush; private SharpDx.Direct2D1.Brush gradientBrush; private SharpDx.RectangleF reuseRect; protected override void OnRender (ChartControl chartControl, ChartScale chartScale) { base,OnRender(chartControl, chartScale); foreach(KeyValuePair<int, SortedDictionary<double,long>> historicdict in rowsArray) { foreach(KeyValuePair<double,long> keyValue in historicdict.Value) { xpos = chartControl.GetXByBarIndex(ChartBars, histroicdict.Key +1) if (RenderTarget != null) { linGrBrush = new LinearGradientBrush(System.Windows.Media.Color.FromRgb(255,255,0), System.Windows.Media.Color.FromRgb(0,128,255), new System.Windows.Point(xpos,0), new System.Windows.Point(xpos-((int)(chartControl.Properties.BarDistance * 20)))); gradientBrush = linGrBrush.ToDxBrush(RenderTarget); } UpdateRect(ref reuseRect, xpos, ymid, xpos-((int)(chartControl.Properties.BarDistance * 20)), height) RenderTarget.FillRectangle(reuseRect, gradientBrush) if (gradientBrush != null) {gradientBrush.Dispose();} } } }
How can I resolve this issue? It is causing my NT to stop working and the entire application crashes.
Comment