wayland/ssd1306-oled-I2c example-scroll failed to compile (Solved)

I’m getting:
error: variable-sized object ‘cString’ may not be initialized
char cString[length(xString) + 1] = { 0 };
^
Compilation failed
Command C:\Users\marti\AppData\Local\Programs\XOD IDE\resources\arduino-cli.exe --config-file=C:\Users\marti\AppData\Local\Temp\arduino-cliJ9wh5l\.cli-config.yml compile --fqbn esp8266:esp8266:nodemcuv2:CpuFrequency=80 --verbose C:\Users\marti\AppData\Local\Temp\xod_temp_sketchbookQirxez\xod_1563004583491_sketch failed with code 1
The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.

How can I fix this?

I changed the code to:
char cString[length(xString)];
and this seemed to work ok.
NB I also removed the + 1 because it was adding an extra character to the end of the text displayed. When WRAP was set to True strange characters appeared at end, this was cured by setting WRAP to False.

Hi Martin,

Many thanks for the feedback. The original code works for the Arduino Uno and I don’t know why it can’t be compiled for the esp8266. I took the code to convert an XString to a C string from here:
https://forum.xod.io/t/convert-xstring-or-list-char-to-char/1495

Hopefully one of the more experienced members of the forum will be able to offer advice.

1 Like

I changed the code and it now seems to be working ok.
Here are the changes I made:
// length returns the number of characters and you need an extra one to keep the
// terminal NUL-character used in C string representation. Initialize to 0’s to
// ensure the last char is indeed NUL
// …following line gave compile error…
// char cString[length(xString) + 1] = { 0 };
// above line changed to below by mb
int N=length(xString) + 1;
char cString[N];
for(int i=0;i<N;i++)
cString[i]=0;
// move the data from XString to the plain C string
dump(xString, cString);

1 Like

Great stuff! I’ve published a new version of the library with your bug fix.

Many thanks,

Matt

1 Like