Scrolling text cuts off 256 characters from end of string

I’m working with a chained of four 16x32 HUB75 panels hooked up to a Teensy 3.6 with the SmartLED v3 shield using the master branch of the SmartMatrix library. It’s receiving commands via USB serial sent from a Raspberry Pi (though I don’t think that part is relevant here).

By default, const int textLayerMaxStringLength = 100; in Layer_Scrolling.h. I need this to be longer, so I bumped it up to 1024. However I am running into some strange issues with longer strings of text.

For example, I call SMLayerScrolling::update with the following:

Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore—While I nodded, nearly napping, suddenly there came a tapping, As of some one gently rapping, rapping at my chamber door. Tis some visitor, I muttered, rapping at my chamber door—Only this and nothing more.

and the text displayed on the LED matrix will be

Once upon a midnight dreary, while I pondered, weak and weary, Over

The cutoff is 256 characters away from the endpoint. If I cut off the beginning of the string, it will still cutoff at the same point, so it is counting backwards from the end somehow.

I am certain at this point that the issue is unrelated to the serial communication - debugging prints show me that the entire string is stored in the Arduino at every point in my program that is calling the SmartMatrix library.

So I suspect the issue is somehow related to string manipulation code. Looking in the code for SMLayerScrolling::update, strncpy is used. I tried strlcpy instead with no luck. But I am a complete noob to C/C++, so I don’t know what the best string practices are.

My program on the Arduino uses strdup to get the string from the Serial port - but again, all the debugging lines show that it has a copy of the entire string. I tried bumping up size of the Teensy’s Serial rx buffer anyways, but it makes no difference.

I’m guessing there is a really simple fix here, but my inexperience leaves me clueless. Thanks in advance for the help!

Incase anyone wants to peek at my code, I think this is the potentially relevant file: Ignore the command struct stuff at the start, I’m doing this the dumb way by just doing a switch on hard coded command names for now.

This variable can only hold 0-255, so you’ll need to change it to a larger type, e.g. unsigned short or uint16_t:

I mentioned to you that SmartMatrix Library 4.0 has an optional new Layer for scrolling text, but it’s not optimized for your use case of scrolling really long strings. The Layer you’re using now allocates memory for the size of the screen. The new GFX Layer needs to allocate memory for the size of the graphics that will be displayed, and in your case a long string, with potentially a large font, could use a lot more memory. Just FYI in case you’re thinking of switching.

Fantastic! I figured it had to be something like that but after enough hours staring at the same problem I tend to get stuck. I am very grateful for your assistance.

Oh I see your response now on my errant pull request on Github. Very cool! I will be definitely be trying out the new version after tonight.