-
-
Notifications
You must be signed in to change notification settings - Fork 81
pybricks.iodevices.LWP3Device: Buffer incoming notifications. #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Allows to read without blocking and allows subscribing to multiple sensor values without losing data.
Yes, we will need to add something like |
|
I did that initially, but couldn't see or reproduce how they would clash if I didn't. We already have Would it be possible for a notification event to come in after we get the disconnect event? |
|
Ah, I missed that we already have So now I think the problem is likely this: pybricks-micropython/pybricks/iodevices/pb_type_iodevices_lwp3device.c Lines 118 to 120 in e34e303
Root pointers only make sense when they point to memory allocated by the garbage collector. The GC will see that this pointer didn't come from the heap and just ignore it. So |
|
Yeah, it would be better to split
I wasn't able to reproduce the crash even by forcing it to collect.
I'll take this approach to keep it simple as per the above note about build size. Thanks for the help! |
It would likely only crash if the same memory blocks were reallocated for a new object and then that object was used later after the memory was written over. |
Allows to read without blocking and allows subscribing to multiple sensor values without losing data.
As an example, here's how you can read both the color and the speed of the Duplo Train:
Fixes pybricks/support#1648
It works well, but it can sometimes crash the hub when stopping the program. Perhaps because of the buffer being freed before the connection is closed, so this might need some more work.
Tagging @NStrijbosch.