Keyboard.write fails after N invocations?

Has anyone ever seen Keyboard.write spontaneously stop working?

I've been happily testing my USB game controller v3 (Due based) and it's all been working very well for the last 30+ minutes. Joystick and Keyboard libraries both doing everything they should.

Then all of a sudden, Keyboard.write stopped working. No keycodes are being sent. Joystick sends are still working.

I will of course reboot and test it again and see whether there is something magical about 32 minutes of run time etc. But thought I would ask whether there is any Well Known Issue that could make Keyboard.write work for a while and then spontaneously stop working.

Here is the code -- pretty simple --

void send_char(char c) {

// sends exactly one key code to Kbrd service
// For now, we will send it to Serial
  Serial.print("\"");Serial.write(c);Serial.print("\"");
  Serial.print(", hex: ");
  // prints value as string in hexadecimal (base 16):
  Serial.println(c, HEX);
  
  if (!hidKill) {Keyboard.write(c);}
  
  return;
  
}

Serial monitor output:

Got a touch on 1.10 at 0,0 (0)
This item is at 221,137 and is 55 x 55
"1", hex: 31
x65 Simple Touch 1:10 = 0

Got a touch on 1.15 at 0,0 (0)
This item is at 221,196 and is 55 x 55
"5", hex: 35
x65 Simple Touch 1:15 = 0

In the example above, neither 1 nor 5 is ever "typed" into a text editor or xterm window, even when focus is in that window. And I verified that hidKill is 0.

Interestingly the Keyboard device might be "jammed" sending just one character over and over again, as while typing this message (on a real keyboard) I am getting occasional long strings of lower case m when I change desktops (OSX). Also I seem to be getting some jumbling of key order when typing on the real keyboard -- "might" comes out "imght" and other words are scrambled, and I touch type very accurately so that's pretty strange. It's all a bit mysterious.

UPDATE: rebooting the Due seems to fix this problem, so at least I can reasonably claim it is local to the Arduino and not some OSX driver "unknown keyboard" issue. Given the run time before failure I suspect it must be (oh dread) a memory management issue of some kind.

Speaking of which, is there any gdb equiv for arduino? if you do suspect a memory management booboo, how do you ever find it?

You wrote "Here is the code" and then showed part of the code. Please show ALL of the code.

Check for array bound violations.

"All" the code would be about 4 thousand lines, a bit much for a forum post :slight_smile:

I tend to agree with jremington, there must be an array bounds stomp somewhere.

There are also several instances of String (yes I know, String is dangerous, but String is also fast and easy to prototype with) which perhaps I should examine more closely.

More testing needed. Just wanted to know if there was a Known Issue with Keyboard library. If there is none, I'll just search doggedly for memory management booboos.

Tazling:
There are also several instances of String (yes I know, String is dangerous, but String is also fast and easy to prototype with) which perhaps I should examine more closely.

Seems as though you know the answer already.