Support Board
Date/Time: Fri, 28 Aug 2026 02:31:18 +0000
[Programming Help] - SCString .Format() and .AppendFormat() causing SC to crash
View Count: 28
| [2026-08-27 21:30:49] |
| drinkcodejava - Posts: 46 |
|
This one has been driving me nuts the past few days. The following custom study causes Sierra Chart to close by itself without saving. I am running SC version 2939 on a non-ARM x64 machine, and compiling using a standard remote build of the DLL. Can anyone duplicate this behavior on their computer? #include "sierrachart.h"
SCDLLName("SCString Format Crash") SCSFExport scsf_SCStringFormatCrash(SCStudyInterfaceRef sc) { // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "SCString Format Crash"; sc.StudyDescription = ""; sc.AutoLoop = 0; // Setting to 1 still results in crash return; } // Section 2 - Do data processing here SCString StudyStr; // Variables for account/trade/position parametrics float CurrMargin = 0.0f, CurrNLV = 0.0f; float Limit_NLV80Pct = 0.0f; CurrNLV = 1000.0f; // Crashes for values >= 999.996 or <=-999.9, but not consistently Limit_NLV80Pct = CurrNLV * 0.80f; StudyStr.Clear(); StudyStr.Format("\nNLV: $%.2f | ", CurrNLV); // Including any leading escaped/special character causes a crash: \t, \n, \", \\, \r, \' StudyStr.AppendFormat(" 80% NLV: %.2f (%.2f)", Limit_NLV80Pct, CurrMargin/Limit_NLV80Pct); // Including the % character after the 80 causes a crash // Commenting out the previous 2 lines and using this following line instead does not cause a crash // StudyStr.Format("\nNLV: $%.2f | 80% NLV: %.2f (%.2f)", CurrNLV, Limit_NLV80Pct, CurrMargin/Limit_NLV80Pct); } If anyone else is able to duplicate this, I think I will try to escalate it from Programming Help, but I just want to make sure I'm not doing something stupid. Thanks! |
| [2026-08-28 01:18:36] |
| User719512 - Posts: 470 |
|
Did you ask AI like Grok or ChatGPT for guidance? This should not take a few days to solve. This is a common pitfall we have all seen, forgotten, mistyped, etc. The % after 80 is a format specifier, not a literal percent. Crashes happen when one forgets to escape %. Escape it as %%: StudyStr.Format("\nNLV: $%.2f | ", CurrNLV); StudyStr.AppendFormat(" 80%% NLV: %.2f (%.2f)", Limit_NLV80Pct, CurrMargin / Limit_NLV80Pct); or keep it in one call: StudyStr.Format("\nNLV: $%.2f | 80%% NLV: %.2f (%.2f)", CurrNLV, Limit_NLV80Pct, CurrMargin / Limit_NLV80Pct); |
To post a message in this thread, you need to log in with your Sierra Chart account:
