Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 07:36:01 +0000



Post From: ACSIL Using Pointers on Subgraph arrays raises CPU exception

[2024-03-29 04:10:10]
User43 - Posts: 101
This is not a programming question, it is a report of an error in SC.
Knowing the problem now, I can work around it in my project, but hopefully you will be able to fix it.

Following sample code raises a CPU exception on the message log when entering the "Add Custom Study" dialog.
See the comments in the code block.

Interestingly the issue occurs only on the Subgraph array. The Input array is not showing this problem although both use the same c_ArrayWrapper.

Using a pointer via
&sc.Subgraph.ElementAt(0)
is ok.

Problem: When using a pointer via
&sc.Subgraph.GetAt(0)
or
sc.Subgraph.GetPointer()
and accessing the element will cause a CPU exception.

2024-03-28 23:18:42.151 | Loading DLL: C:\SierraChart\Data\scPointerProblem.dll (scPointerProblem_64.dll). Handle: 7ff958470000
2024-03-28 23:18:42.151 | Warning: The Custom DLL study "scPointerProblem.scsf_SC_Subgraph_Pointer_Issue" has just caused a CPU exception.
2024-03-28 23:18:42.151 | Warning: This Custom DLL study may cause Sierra Chart to be unstable until you remove the study from the chart and restart Sierra Chart.


// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("SC Subgraph Pointer Issue")


SCSFExport scsf_SC_Subgraph_Pointer_Issue(SCStudyInterfaceRef sc)
{
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "Subgraph Pointer issue test";
sc.StudyDescription = "Setting subgraphs using pointers does not work.";
    
// Set the region to draw the graph in. Region zero is the main
// price graph region.
sc.AutoLoop = 0; // Manual Looping
sc.GraphRegion = 0;
sc.ValueFormat = 0;
sc.UpdateAlways = 0;


SCSubgraphRef subg = sc.Subgraph[0];
subg.Name = "Chart Scale";
subg.LineWidth = 3;
subg.DrawStyle = DRAWSTYLE_LINE;
subg.PrimaryColor = RGB(0, 128, 255); //Blue
subg.SecondaryColor = RGB(0, 0, 0); //black
subg.SecondaryColorUsed = true;
subg.DisplayNameValueInWindowsFlags = 1;

// ---->> THIS IS RAISING AN EXCEPTION WHEN USING GetAt
// WHEN USING ElementAt is used no exception is raised
// s_SCSubgraph_260* subgP = &sc.Subgraph.ElementAt(0);
s_SCSubgraph_260* subgP = &sc.Subgraph.GetAt(0);
subgP++;
subgP->Name = "Set via pointer from sc.Subgraph.GetPointer()";
subgP->LineWidth = 3;
subgP->DrawStyle = DRAWSTYLE_LINE;
subgP->PrimaryColor = RGB(128, 128, 255);
subgP->SecondaryColor = RGB(0, 0, 0); //black
subgP->SecondaryColorUsed = false;
subgP->DisplayNameValueInWindowsFlags = 1;


SCInputRef inp = sc.Input[0];
inp.Name = "Input via sc.Inpput[0]";
inp.SetInt(55);

// ---->> THIS IS NOT RAISING AN EXCEPTION
// s_SCInput_145* inpP = &sc.Input.ElementAt(0);
s_SCInput_145* inpP = &sc.Input.GetAt(0);
inpP++;
inpP->Name = "Input via pointer from GetAt()";
inpP->SetInt(99);

// Must return before doing any data processing if sc.SetDefaults is set
return;
}  
}

I'm on SC 2625.