compiled module crashes Rack linux

Quick on here, I can compile but it core dump Rack when I try to load my plugin:

Rack: src/app/ModuleWidget.cpp:130: void rack::app::ModuleWidget::addOutput(rack::app::PortWidget*): Assertion `!output2' failed.
Aborted (core dumped)

code from the plugin:

#include "plugin.hpp"


struct Sun : Module {
	float phase = 0.f;
	enum ParamId {
		VOLUME_PARAM,
		PARAMS_LEN
	};
	enum InputId {
		PITCH_INPUT,
		INPUTS_LEN
	};
	enum OutputId {
		LEFTOUT_OUTPUT,
		OUTPUTS_LEN
	};
	enum LightId {
		LIGHTS_LEN
	};

	Sun() {
		config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
		configParam(VOLUME_PARAM, 0.f, 1.f, 0.f, "");
		configParam(VOLUME_PARAM, 0.f, 1.f, 0.f, "");
		configInput(PITCH_INPUT, "");
		configOutput(LEFTOUT_OUTPUT, "");
	}

	void process(const ProcessArgs& args) override {
		float pitch = 126.27;
		float freq = dsp::FREQ_C4 * std::pow(2.f, pitch);

		// Accumulate the phase
		phase += freq * args.sampleTime;
		if (phase >= 0.5f)
			phase -= 1.f;

		// Compute the sine output
		float sine = std::sin(2.f * M_PI * phase);
		// Audio signals are typically +/-5V
		// https://vcvrack.com/manual/VoltageStandards
		outputs[LEFTOUT_OUTPUT].setVoltage(5.f * sine);
	}
};


struct SunWidget : ModuleWidget {
	SunWidget(Sun* module) {
		setModule(module);
		setPanel(createPanel(asset::plugin(pluginInstance, "res/Sun.svg")));

		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));

		addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(5.211, 4.756)), module, Sun::VOLUME_PARAM));
		addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(5.211, 14.308)), module, Sun::VOLUME_PARAM));

		addInput(createInputCentered<PJ301MPort>(mm2px(Vec(3.723, 32.994)), module, Sun::PITCH_INPUT));

		addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.181, 32.994)), module, Sun::LEFTOUT_OUTPUT));
		addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.181, 35.953)), module, Sun::LEFTOUT_OUTPUT));
	}
};


Model* modelSun = createModel<Sun, SunWidget>("Sun");

You have configParam(VOLUME_PARAM twice. Don’t know if that’s the cause, but…

Oh, and same with addParam

you were faster than me!! yep finally caught that! Thanks!

One more last thing, when I change my SVG - is there a way to update the CPP without losing all the code I’ve added to it?

I’ve not found a way, but if you have only changed the layout, you can create a new module with the helper.py, and you should be able to paste the Widget constructor code from that, into your SunWidget.

Thanks, I realize that I should get the layout well done first, compile and test with the output and all the design… once that is clean then I can start working on the logic/programing.

best not to use helper.py for a “real” plugin, perhaps?

how would you go about transforming the svg to cpp code? Just manually?

Yes, just manually. Most people still use svg to provide the graphics, but they manually declare the enums for the ports, params and lights, and they would manually specify the vectors for placing the ports etc in the Widget constructor.

Unless you get your panel placement just right first time round.

Yes, thanks. That is a much more complete answer. Fwiw, I’ve never used the helper, even to start a module. But that’s habit more than anything else.

Would it make sense to have the svg → cpp in a different file that is referenced by the main code. Now here I am not versed in C++ at all so I am not too sure how that would work, but separating the visual aspect of the code with the main logic of the code could make it simpler to have the helper helps :smiley:

1 Like

I’ve found its easy to save the code, re-do helper, and then add back in the saved code

We don’t use the helper, so can’t really speak to how it could be made better. You don’t need the helper, but if you want to use it, that’s fine.