Struct has no member named NumParams/NumInputs/NumOutputs

Hi @danngreen

Trying to do a new plugin port and running into the following errors:

/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh: In instantiation of 'constexpr ElementCount::Counts ElementCount::count(auto:48) [with auto:48 = SlideSwitch]':
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:65:45:   required from 'ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)> [with auto:49 = SlideSwitch]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2559:26:   required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Args = {const SlideSwitch&}]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2570:55:   required from 'struct std::__result_of_impl<false, false, ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const SlideSwitch&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2575:12:   required from 'struct std::__invoke_result<ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const SlideSwitch&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:3029:12:   required from 'struct std::invoke_result<ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const SlideSwitch&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:3041:11:   required by substitution of 'template<class _Fn, class ... _Args> using invoke_result_t = typename std::invoke_result::type [with _Fn = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Args = {const SlideSwitch&}]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/variant:1102:14:   required from 'constexpr bool std::__detail::__variant::__check_visitor_results(std::index_sequence<_Idx ...>) [with _Visitor = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Variant = const std::variant<MetaModule::NullElement, MetaModule::ImageElement, MetaModule::ParamElement, MetaModule::Knob, MetaModule::Slider, MetaModule::SliderLight, FlipSwitch, SlideSwitch, MetaModule::MomentaryButton, MomentaryButtonLight, MomentaryButtonRGB, LatchingButton, Encoder, EncoderRGB, JackInput, JackOutput, MonoLight, DualLight, RgbLight, TextDisplay, DynamicTextDisplay, DynamicGraphicDisplay, AltParamContinuous, AltParamChoice, AltParamChoiceLabeled>&; unsigned int ..._Idxs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; std::index_sequence<_Idx ...> = std::integer_sequence<unsigned int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24>]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/variant:1843:44:   required from 'constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Variants = {const variant<MetaModule::NullElement, MetaModule::ImageElement, MetaModule::ParamElement, MetaModule::Knob, MetaModule::Slider, MetaModule::SliderLight, FlipSwitch, SlideSwitch, MetaModule::MomentaryButton, MomentaryButtonLight, MomentaryButtonRGB, LatchingButton, Encoder, EncoderRGB, JackInput, JackOutput, MonoLight, DualLight, RgbLight, TextDisplay, DynamicTextDisplay, DynamicGraphicDisplay, AltParamContinuous, AltParamChoice, AltParamChoiceLabeled>&}; __detail::__variant::__visit_result_t<_Visitor, _Variants ...> = ElementCount::Counts]'
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:65:19:   required from here
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:25: error: 'struct SlideSwitch' has no member named 'NumParams'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                       ~~^~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:38: error: 'struct SlideSwitch' has no member named 'NumLights'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                                    ~~^~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:51: error: 'struct SlideSwitch' has no member named 'NumInputs'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                                                 ~~^~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:64: error: 'struct SlideSwitch' has no member named 'NumOutputs'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                                                              ~~^~~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh: In instantiation of 'constexpr ElementCount::Counts ElementCount::count(auto:48) [with auto:48 = MomentaryButtonLight]':
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:65:45:   required from 'ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)> [with auto:49 = MomentaryButtonLight]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2559:26:   required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Args = {const MomentaryButtonLight&}]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2570:55:   required from 'struct std::__result_of_impl<false, false, ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const MomentaryButtonLight&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:2575:12:   required from 'struct std::__invoke_result<ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const MomentaryButtonLight&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:3029:12:   required from 'struct std::invoke_result<ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>, const MomentaryButtonLight&>'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/type_traits:3041:11:   required by substitution of 'template<class _Fn, class ... _Args> using invoke_result_t = typename std::invoke_result::type [with _Fn = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Args = {const MomentaryButtonLight&}]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/variant:1102:14:   required from 'constexpr bool std::__detail::__variant::__check_visitor_results(std::index_sequence<_Idx ...>) [with _Visitor = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Variant = const std::variant<MetaModule::NullElement, MetaModule::ImageElement, MetaModule::ParamElement, MetaModule::Knob, MetaModule::Slider, MetaModule::SliderLight, FlipSwitch, SlideSwitch, MetaModule::MomentaryButton, MomentaryButtonLight, MomentaryButtonRGB, LatchingButton, Encoder, EncoderRGB, JackInput, JackOutput, MonoLight, DualLight, RgbLight, TextDisplay, DynamicTextDisplay, DynamicGraphicDisplay, AltParamContinuous, AltParamChoice, AltParamChoiceLabeled>&; unsigned int ..._Idxs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; std::index_sequence<_Idx ...> = std::integer_sequence<unsigned int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24>]'
/Applications/ArmGNUToolchain/12.3.rel1/arm-none-eabi/arm-none-eabi/include/c++/12.3.1/variant:1843:44:   required from 'constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = ElementCount::count(const MetaModule::Element&)::<lambda(auto:49)>; _Variants = {const variant<MetaModule::NullElement, MetaModule::ImageElement, MetaModule::ParamElement, MetaModule::Knob, MetaModule::Slider, MetaModule::SliderLight, FlipSwitch, SlideSwitch, MetaModule::MomentaryButton, MomentaryButtonLight, MomentaryButtonRGB, LatchingButton, Encoder, EncoderRGB, JackInput, JackOutput, MonoLight, DualLight, RgbLight, TextDisplay, DynamicTextDisplay, DynamicGraphicDisplay, AltParamContinuous, AltParamChoice, AltParamChoiceLabeled>&}; __detail::__variant::__visit_result_t<_Visitor, _Variants ...> = ElementCount::Counts]'
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:65:19:   required from here
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:25: error: 'struct MomentaryButtonLight' has no member named 'NumParams'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                       ~~^~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:51: error: 'struct MomentaryButtonLight' has no member named 'NumInputs'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                                                 ~~^~~~~~~~~
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/element_counter.hh:61:64: error: 'struct MomentaryButtonLight' has no member named 'NumOutputs'
   61 |         return Counts{e.NumParams, e.NumLights, e.NumInputs, e.NumOutputs};
      |                                                              ~~^~~~~~~~~~

I am checked out to the api-v2.0-dev-13 tag in metamodule-plugin-sdk - not sure if I am doing something wrong or am missing something obvious.

Thanks in advance.

I see the error is about SlideSwitch not having a member NumParams. It does (look in base_element.hh where its defined), so maybe SlideSwitch is defined in the new plugin project somewhere?

If not, then check the #includes of the file that’s getting the error (CoreModules/elements/element_counter.hh). It includes CoreModules/elements/elements.hh, so check that file is not modified. Then, elements.hh includes CoreModules/elements/base_element.hh, and check to make sure that file is in place and is not modified. If you look in that last file, you’ll see the definition of SlideSwitch, which ultimately inherits from BaseElement, which does indeed define those members (NumParams, NumInputs, etc…).

Thanks for the tips - took a look and didn’t find anything out of the ordinary re: both the SlideSwitch and differences between element_counter or elements.hh

Not sure if this is helpful? I see some more upstream errors:

/Users/ericgao/Documents/Projects/ports/Via/Via-for-Rack/Via/io/inc/via-virtual-system.hpp:67:18: error: expected identifier before numeric constant
/Users/ericgao/Documents/Projects/ports/Via/Via-for-Rack/Via/io/inc/via-virtual-system.hpp:67:18: error: expected '}' before numeric constant
/Users/ericgao/Documents/Projects/ports/Via/Via-for-Rack/Via/io/inc/via-virtual-system.hpp:67:18: error: expected unqualified-id before numeric constant
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:107:26: error: 'State_t' does not name a type; did you mean 'mbstate_t'?
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:110:45: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:113:47: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:121:32: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:131:30: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:154:31: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:161:35: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:172:36: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:204:38: error: expected class-name before '{' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/CoreModules/elements/base_element.hh:227:1: error: expected declaration before '}' token
/Users/ericgao/Documents/Projects/ports/metamodule-plugin-sdk/metamodule-core-interface/./CoreModules/elements/elements.hh:59:67: error: cannot convert 'FlipSwitch' to 'float' in initialization

That sounds like a syntax error in that file.

Yeah I completely misread this, sorry. I thought it was an error still in base_elements - thanks this fixed it.

1 Like

unfortunately got this to compile, but when loading it into MM dev13 it just freezes the plugin load screen and I have to power cycle it.

I sent an invite to you to collaborate - if you would have some time or pointers as to how to debug a load-time crash that would be very helpful!

Thanks

1 Like

I started working on this. First, there were some errors with RELEASED and PRESSED being #defined, so I got rid of the #defines and changed them to

constexpr int PRESSED = 1;
constexpr int RELEASED = 0;

I don’t think they were being used, but it’s in the upstream repo (GitHub - starlingcode/Via: Cross-platform library for the Via modules) so I can’t push those changes. You must have gotten around this already yourself, too

Next, I saw the crashing on load, and I thought the best way would be to run it in the simulator.

First, I looked at the CMakeLists file and updated the boilerplate “METAMODULE_SDK_DIR” variable checking to a newer version I have which gives precedence to using a cmake variable to set this path. Not strictly necessary, but this makes for less surprises if you go back and forth between simulator and plugin.

Then I changed the cmake library name from “Via” to “Starling_Via”. It was fine the way you had it, but the simulator is picky about external project library names and it has to match the brand slug exactly.

Then I did the thing you have to do to all plugins to make them run in the simulator (in starling.cpp: add extern to the pluginInstance declaration and change init to init_Starling_Via). I don’t have push access to that repo, but it’s the same thing documented here in the simulator docs

Finally, I had to get rid of this:

Add custom libc implementations
set(LIBC_SOURCES
     ${METAMODULE_SDK_DIR}/metamodule-plugin-libc/newlib/libc/ctype/jp2uc.c
 )

What’s this file used for? It seems to build the .mmplugin ok with or without this. But the simulator definitely doesn’t like it, so I commented it out so I could keep going.

At this point I got it to compile in the simulator. And it crashes immediately. So then I ran make debug from the simulator directory, and right away it crashes on this line:

At the moment of the crash on my system, i = 11225, which means it’s trying to access 517*11225 = 5 million bytes past tableRead
… I’m pretty sure the table is not 5MB, so that would be an error

Looking a bit more, it says table->numWaveforms = 0. The outer for loop goes up to table->numWaveforms - 1, and numWaveforms is unsigned, so yep, that’s the problem.
Somewhere the table is not getting setup correctly.

Tracing the stack back, I see this is called from switchWavetable in meta.hpp, which is called in meta-modes.cpp here:

In this call, we see the wave table we’re trying to read is actually the wavetableArray member of our ViaMeta class. But it’s all 0’s, so somewhere it’s not getting setup properly.

Then poking around a bit more, I see that this wavetableArray is supposed to be initialized in a function called readTableSetFromFile:

Hmm… that TODO looks interesting…
This function is called from the constructor of ViaMeta, which is constructed by the VCV Rack module. The path to a file is passed into that constructor:

Aha! That file is not in the assets/ dir! So when the module is constructed, it tries to read the file but it fails. There’s no error checking or anything in the code, so it just continues along and eventually crashes somewhere else.

So I copied this file to assets/, and ran the simulator again (after fiddling with the file path just to get the simulator to cross from the fake metamodule filesystem to the real computer filesystem)

And… that was it! It loads now!

You can see all the changes I made (except for the RELEASED thing, and the init => init_Starling_Via thing) in the dg-main branch:

1 Like

This was unbelievably helpful, thank you for such a thorough writeup! I’ll have to get more comfortable with simulator debugging for sure. I also keep forgetting to fully bring over all non-SVG assets from the res directories…

Will merge your PR in and test/create a release for these!

Regarding that odd jp2uc line… I tried to fix this missing symbol originally:

Symbol in plugin not found in api: _jp2uc_l

I thought I had to stub it, but realized it existed in the metamodule-plugin-sdk later. I’m not sure why I had to manually define a link to jp2uc.c though.

Yeah, it gets me a lot, too. But you don’t want to blindly copy all non-svg files-- just the ones that are used. Space is limited on the MM and loading the plugin from disk can be slow – so only copying in the files that are actually used will make the plugin load fast, and use less RAM.