timower / rM2-stuff

Collection of reMarkable related apps, utilities and libraries.
GNU General Public License v3.0
125 stars 10 forks source link

shiftKey, ctrlKey and altKey addresses change #2

Closed khanhas closed 3 years ago

khanhas commented 3 years ago

First of all, great work on porting yaft to reMarkable. It's so light and fast, keyboard works with 0 visual delay and I love it so much!

So I tried to add more keys on another row to the list. Unfortunately, a bug consistently happened that Ctrl, shift and alt are always on. It led to invalid key and Segmentation fault all the time whenever I hit something (except ctrl, shift and alt tho). After a "few" hours investigating, the bug is due to you using addresses of elements in vector<Key> keys for shiftKey, ctrlKey and altKey. These addresses are potentially changed after emplacing more elements to the vector.

Unless vector are reserved enough memory space prior any emplacing operation, vector would reallocate all elements to new space. To prevent bugs in the future, you can either:

keys.reserve(num_rows * row_size);

Or use std::vector<Key>::iterator instead of address.

timower commented 3 years ago

Thanks, indeed I shouldn't use pointers (or iterators btw they just wrap the pointer). Reserving the keys would work, but I'll just store indices and add helper functions to get a key reference.

timower commented 3 years ago

Can you test the latest master, I now store indices instead of pointers. (you can get a compiled build here)

khanhas commented 3 years ago

Good work. I saw no segfault during10m playing around with it.

timower commented 3 years ago

Fixed by bcc2487cf90803c54c8b08b42522b8079f38d230