grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.58k stars 322 forks source link

Teensy 4.1: crash on passing invalid parameter path #834

Closed hatchjaw closed 1 year ago

hatchjaw commented 1 year ago

For a faust program with, e.g.

gain = hslider("gain", 1, 0, 1, .01);

then from a Teensy sketch calling

g.setParamValue("gain?", .5);

Teensy reboots and produces a crash report:

CrashReport:
  A problem occurred at (system time) 16:14:20
  Code was executing from address 0x14C0C
  CFSR: 82
    (DACCVIOL) Data Access Violation
    (MMARVALID) Accessed Address: 0x2 (nullptr)
      Check code at 0x14C0C - very likely a bug!
      Run "addr2line -e mysketch.ino.elf 0x14C0C" for filename & line number.
  Temperature inside the chip was 35.92 °C
  Startup CPU clock speed is 600MHz
  Reboot was caused by auto reboot after fault or bad interrupt detected

Running addr2line returns Teensy's Print.cpp, but not the line number.

This appears to be an issue with the call to fprintf in get/setParamValue(). In this ancient thread from the PJRC forum, Paul Stoffregen strongly advises using Serial.printf instead. Likely this still applies.

Minimal example to reproduce attached. param-crash-test.tar.gz

Thanks!

sletz commented 1 year ago

The problematic code is there https://github.com/grame-cncm/faust/blob/master-dev/architecture/faust/gui/MapUI.h#L159 and https://github.com/grame-cncm/faust/blob/master-dev/architecture/faust/gui/MapUI.h#L179. So we may have to do something like:

#ifdef TEENSY_DRIVER 
Serial.printf(...) // to complete
#else 
fprintf(stderr, "ERROR : setParamValue '%s' not found\n", str.c_str());
#endif

Same for getParamValue.

Can you possibly try in this direction ?

hatchjaw commented 1 year ago

Thanks. I was thinking it might be preferable to inherit from MapUI (e.g. TeensyMapUI) and override get/setParamValue, but I see that if MIDICTRL is defined there are a large number of further calls to fprintf, inserted from SimpleParser, dsp-adapter, etc.

So, I've submitted a PR that uses the preprocessor to substitute fprintf with Serial.printf.

sletz commented 1 year ago

Even better, thanks for the PR.