Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Attempted to read or write protected memory. This is often an indication that other m
Collapse
X
-
Attempted to read or write protected memory. This is often an indication that other m
I am getting the following error and have exhausted all ideas on what might be the issue:
I have attached an export of the Indicator. It's an attempt at a function to draw candlesticks.Code:Last edited by swcooke; 09-04-2018, 08:15 AM.Tags: None
-
Hello swooke,
Thanks for your post.
This error is typically seen with an issue with SharpDX resource management. At first glance, I see that you are (re)creating brushes in OnRenderTargetChange() and then disposing them immediately after. Brushes should be disposed of and then recreated in OnRenderTargetChange().
If you do not wish to re-use brushes (advised best practice) and create the brushes in OnRender() before they are used, the brushes would need to be disposed of at the end of the OnRender() pass.
I've provided links to further reading on SharpDX rendering and an example which draws candlesticks which could be used for further direction.
SharpDX Rendering - https://ninjatrader.com/support/help..._rendering.htm
HeikenAshi8 - https://ninjatrader.com/support/foru...tid=-1&lpage=1
Additional examples on re-using SharpDX brushes can be found here - https://ninjatrader.com/support/foru...144#post509144
Please let us know if there is anything else we can do to help.
-
On a related note, I noticed that the HeikenAshi example you provided uses, for example, this for a down bar color:
I am using this:Code:[XmlIgnore] [Display(Name="BarColorDown", Description="Color of Down bars", Order=2, GroupName="Visual")] public Brush BarColorDown { get { return barColorDown;} set { barColorDown = value;} }
Is all of the complexity in my set block really needed? I realize the example shared was for example purposes but which way is correct for a production indicator?Code:[XmlIgnore] [Display(Name = "Down Candle", GroupName = "Technology(XLK)", Order = 2)] public System.Windows.Media.Brush XlkDownCandleBrush { get { return xlkDownCandleBrush; } set { xlkDownCandleBrush = value; if (xlkDownCandleBrush != null) { if (xlkDownCandleBrush.IsFrozen) { xlkDownCandleBrush = xlkDownCandleBrush.Clone(); xlkDownCandleBrush.Freeze(); } } } }
Comment
-
Hello swooke,
You may observe the syntax the NinjaScript code generators create for Brush properties for a minimalist implementation.
For example, right click on the indicators folder in the NinjaScript Editor and select New Indicator. From the New Indicator Wizard, add a Brush property under Input parameters and then click Generate.
Further reading on the syntax generated for Brushes and how they can be serialized can be found in the tip article below. Serialization is necessary to save the Brush to xml files. (So they can be saved in Templates and Workspaces)
User Defined Brushes - https://ninjatrader.com/support/help...lor_inputs.htm
I've also included reference for working with brushes to better understand when a brush would need to be frozen.
Working with Brushes - https://ninjatrader.com/support/help...th_brushes.htm
Please let us know if we can be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
562 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
325 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment