Sorry, my mistake. I thought I saw a reference to the WEB IDE in one of your posts. I’m not sure what the issue is. Unfortunately I don’t have a rotary encoder or Leonardo board, so I can’t do much testing. I was able to upload your patch to an Arduino Uno using the XOD IDE.
I saw on another thread (Error on Leonardo deployment) that someone encountered a similar issue when using a leonardo board and it seemed to relate to a faulty USB port on their PC.