Skip to content

Commit

Permalink
DualDelay: Fix a crash in VST
Browse files Browse the repository at this point in the history
Font for the displays need to be fetched each frame inside draw().
  • Loading branch information
netboy3 committed Dec 1, 2021
1 parent a93513a commit 0f2cb2b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"slug": "MSM",
"name": "MSM",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",
"brand": "MSM",
"author": "Phal-anx, Netboy3",
Expand Down
93 changes: 50 additions & 43 deletions src/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ void Delay::process(const ProcessArgs& args) {
struct DisplayWidget : TransparentWidget {

int *value = nullptr;
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));

DisplayWidget()
{
Expand All @@ -532,37 +531,39 @@ struct DisplayWidget : TransparentWidget {
nvgStrokeColor(args.vg, borderColor);
nvgStroke(args.vg);
// text
nvgFontSize(args.vg, 16);
nvgFontFaceId(args.vg, font->handle);
nvgTextLetterSpacing(args.vg, 2.5);

std::stringstream to_display;
if (value) {
to_display << std::left << std::setw(5) << *value;
} else {
to_display << std::left << std::setw(5) << 500;
}

Vec textPos = Vec(3.0f, 17.0f);

NVGcolor textColor = nvgRGB(12, 216, 255);
nvgFillColor(args.vg, nvgTransRGBA(textColor, 16));
nvgText(args.vg, textPos.x, textPos.y, "", NULL);

textColor = nvgRGB(0xda, 0xe9, 0x29);
nvgFillColor(args.vg, nvgTransRGBA(textColor, 16));
nvgText(args.vg, textPos.x, textPos.y, "", NULL);

textColor = nvgRGB(12, 216, 255);
nvgFillColor(args.vg, textColor);
nvgText(args.vg, textPos.x, textPos.y, to_display.str().c_str(), NULL);
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));
if (font) {
nvgFontSize(args.vg, 16);
nvgFontFaceId(args.vg, font->handle);
nvgTextLetterSpacing(args.vg, 2.5);

std::stringstream to_display;
if (value) {
to_display << std::left << std::setw(5) << *value;
} else {
to_display << std::left << std::setw(5) << 500;
}

Vec textPos = Vec(3.0f, 17.0f);

NVGcolor textColor = nvgRGB(12, 216, 255);
nvgFillColor(args.vg, nvgTransRGBA(textColor, 16));
nvgText(args.vg, textPos.x, textPos.y, "", NULL);

textColor = nvgRGB(0xda, 0xe9, 0x29);
nvgFillColor(args.vg, nvgTransRGBA(textColor, 16));
nvgText(args.vg, textPos.x, textPos.y, "", NULL);

textColor = nvgRGB(12, 216, 255);
nvgFillColor(args.vg, textColor);
nvgText(args.vg, textPos.x, textPos.y, to_display.str().c_str(), NULL);
}
}
};

struct TRatioADisplay : TransparentWidget {

Delay *module{};
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));;

TRatioADisplay()
{
Expand All @@ -582,16 +583,20 @@ struct TRatioADisplay : TransparentWidget {
nvgStrokeColor(vg, borderColor);
nvgStroke(vg);

nvgFontSize(vg, 16);
nvgFontFaceId(vg, font->handle);
nvgTextLetterSpacing(vg, -2);
// Text
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));;
if (font) {
nvgFontSize(vg, 16);
nvgFontFaceId(vg, font->handle);
nvgTextLetterSpacing(vg, -2);

Vec textPos = Vec(3.0f, 17.0f);
Vec textPos = Vec(3.0f, 17.0f);

nvgFillColor(vg, nvgRGB(12, 216, 255));
char text[128];
snprintf(text, sizeof(text), "%s", module->divisionNames[division]);
nvgText(vg, textPos.x, textPos.y, text, NULL);
nvgFillColor(vg, nvgRGB(12, 216, 255));
char text[128];
snprintf(text, sizeof(text), "%s", module->divisionNames[division]);
nvgText(vg, textPos.x, textPos.y, text, NULL);
}
}
}

Expand All @@ -605,7 +610,6 @@ struct TRatioADisplay : TransparentWidget {
struct TRatioBDisplay : TransparentWidget {

Delay *module{};
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));

TRatioBDisplay()
{
Expand All @@ -626,16 +630,19 @@ struct TRatioBDisplay : TransparentWidget {
nvgStrokeColor(vg, borderColor);
nvgStroke(vg);

nvgFontSize(vg, 16);
nvgFontFaceId(vg, font->handle);
nvgTextLetterSpacing(vg, -2);
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Fonts/Crysta.ttf"));
if (font) {
nvgFontSize(vg, 16);
nvgFontFaceId(vg, font->handle);
nvgTextLetterSpacing(vg, -2);

Vec textPos = Vec(3.0f, 17.0f);
Vec textPos = Vec(3.0f, 17.0f);

nvgFillColor(vg, nvgRGB(12, 216, 255));
char text[128];
snprintf(text, sizeof(text), "%s", module->divisionNames[division]);
nvgText(vg, textPos.x, textPos.y, text, NULL);
nvgFillColor(vg, nvgRGB(12, 216, 255));
char text[128];
snprintf(text, sizeof(text), "%s", module->divisionNames[division]);
nvgText(vg, textPos.x, textPos.y, text, NULL);
}
}
}

Expand Down

0 comments on commit 0f2cb2b

Please sign in to comment.