Login Page - Create Account

Support Board


Date/Time: Wed, 07 May 2025 15:46:27 +0000



Post From: 4 Fonts and 5 Sizes hangs Sierra with sc.Graphics.DrawTextAt()

[2024-11-27 23:16:36]
User719512 - Posts: 310
4 Fonts and 5 Sizes hangs Sierra with sc.Graphics.DrawTextAt()
4 Fonts and 4 Sizes works as expected.

I created a small sample to easily look at some different fonts and sizes. Much to my surprise, this trivial code causes Sierra to hang.

Sometimes you might see one or two clicks or hovers with mouse or keyboard events work, but they might also take minutes to respond. During this time, charts and data will update as seen by the real-time clock, price updates, and file/network updates from Sysintenrals Process Monitor, but you cannot interact with the charts or the Sierra menus.

Attached is an image showing 2 charts.
The first/left one has the clock to see what's updating.
The second/right has a custom study built with the code below.

REPRO and IMPORTANT INFO:
Close all other Chartbooks before running this repro.
Create a new chartbook up with 2 charts like the repro image and SAVE it.
Build/Add the custom study to see (at least on my machine) 4 fonts and 4 sizes working.
(the defaults are 1 and 1 to ensure creation works first time)
SAVE this version of the chartbook.
Edit the study to show 4 fonts and 5 sizes. (other combos might break Sierra as well)
Hit OK to close all the dialogs...
RESULT: Sierra will now be hung and will need to be terminated from Task Manager


Code to repro the issue:


#include "sierrachart.h"

#include <vector>
using namespace std;

SCDLLName("Sierra Font Sample");

namespace ns_zzz_TestSierraFonts
{
static std::vector<SCString> FontNames = {
"Arial"
, "Tahoma"
, "Segoe UI"
, "Consolas"
, "Courier New"
};

static std::vector<int> FontSizes = {
6
,7
,8
,9
,10
,11
,12
};

//
// DrawToChart
//
void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc)
{
const int region_left = sc.StudyRegionLeftCoordinate;
const int region_top = sc.StudyRegionTopCoordinate;

const char* OutputFormatString = "%s size:%d - Showing 4 Fonts and 4 Sizes works. Changing to 5 Sizes will hang Sierra.";

sc.Graphics.SetTextAlign(TA_NOUPDATECP);
SCString output;
int x = region_top + 50;
int y = region_left + 50;

n_ACSIL::s_GraphicsColor backgroundColor;
backgroundColor.SetColorValue(sc.ChartBackgroundColor);

n_ACSIL::s_GraphicsColor textColor;
textColor.Color.RawColor = COLOR_GRAY;
sc.Graphics.SetTextColor(textColor);
sc.Graphics.SetBackgroundMode(TRANSPARENT);

SCInputRef Input_NumFonts = sc.Input[0];
SCInputRef Input_NumSizes = sc.Input[1];

int fontIndex = 0;
int sizeIndex = 0;

for (auto& font : FontNames)
{
n_ACSIL::s_GraphicsFont graphicsFont;
graphicsFont.m_FaceName = font;

sizeIndex = 0;

for (auto& size : FontSizes)
{
output.Format(OutputFormatString, font.GetChars(), size);

graphicsFont.m_Height = size;
sc.Graphics.SetTextFont(graphicsFont);

n_ACSIL::s_GraphicsSize graphicsSize;
sc.Graphics.GetTextSize(output, graphicsSize);

n_ACSIL::s_GraphicsRectangle rect;
rect.Left = x;
rect.Top = y;
rect.Right = x + graphicsSize.Width;
rect.Bottom = y + graphicsSize.Height;

sc.Graphics.FillRectangleWithColor(rect, backgroundColor);
sc.Graphics.DrawTextAt(output, x, y);

//
y += graphicsSize.Height + 4;

++sizeIndex;
if (sizeIndex >= FontSizes.size() || sizeIndex >= Input_NumSizes.GetInt()) break;
}

++fontIndex;
if (fontIndex >= FontNames.size() || fontIndex >= Input_NumFonts.GetInt()) break;
}
}

//
// scsf_zzz_TestSierraFonts
//
SCSFExport scsf_zzz_TestSierraFonts(SCStudyInterfaceRef sc)
{
SCInputRef Input_NumFonts = sc.Input[0];
SCInputRef Input_NumSizes = sc.Input[1];

if (sc.SetDefaults)
{
sc.GraphName = "zzz_TestSierraFonts";
sc.AutoLoop = 0;
sc.DrawZeros = 0;
sc.GraphRegion = 0;
sc.DrawStudyUnderneathMainPriceGraph = 0;
sc.UpdateAlways = 1;

Input_NumFonts.Name = "Num Fonts";
Input_NumFonts.SetInt(1);
Input_NumFonts.SetIntLimits(1, 5);

Input_NumSizes.Name = "Num Sizes";
Input_NumSizes.SetInt(1);
Input_NumSizes.SetIntLimits(1, 7);

return;
}

sc.p_GDIFunction = DrawToChart;

for (int barIndex = sc.UpdateStartIndex; barIndex < sc.ArraySize; barIndex++)
{
// do work...
}
}

} // ns_zzz_TestSierraFonts

imageScreenshot 2024-11-27 150553.png / V - Attached On 2024-11-27 23:10:54 UTC - Size: 171.26 KB - 60 views