Closed AHurnell closed 9 months ago
The problem is that if "aPointer.pointee" doesn't have a real value the app crashes. I've added an if function that checks the memory address of aPointer. Perhaps there is a more elegant way of doing this that someone could suggest.
I think that the function "readUInt8Value" in characteristic reader should be changed to this...
static func readUInt8Value(ptr aPointer : inout UnsafeMutablePointer
I found another example of a similar issue. In the CSCViewController.swift file around line 346.
So there's a general problem with unsafemutable pointers, if they are undefined a device can crash the app.
Thank you for the report. v6 of nRF-Toolbox is under development. It will be fixed there.
I've noticed the app crashing with the following error message...
"Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)" error in utilities/CharacteristicReader.swift at line 42 "let val = aPointer.pointee".
I think if the peripheral device feeds the app bad data it causes this crash. I think this could be handled more safely by checking that aPointer.pointee is a meaningful value of the correct type.
The badly configured peripheral I'm using is a particle argon using a health thermometer example. The exact sequence of events that causes this crash is that
1) The peripheral is connected. 2) The firmware on the peripheral changes to a different file. 3) The phone app attempts to reconnect, I suspect it attempts to use "apointer" value that it has in a cache. 4) The battery level cannot be checked because "apointer" is not set.
You can overcome it by setting val to 0 and connecting to the device. After that val can be returned to "aPointer.pointee" and the app works fine.
So to fix this issue I think the app should check that "apointer.pointee" is a meaningful value, and if not set val to 0. I'll try to do that.