Closed ba58smith closed 3 years ago
Thanks for pointing this out. It looks like memory alignment issue. Could you check the following 2 alternatives and let me know about results (if it crashes or no):
Relplace lines 157-160 in OneWire.h
private:
bool _srch_done;
uint8_t _ow_buf[sizeof(OneWireNg_CurrentPlatform)];
OneWireNg *_ow;
to
private:
uint8_t _ow_buf[sizeof(OneWireNg_CurrentPlatform)];
bool _srch_done;
OneWireNg *_ow;
Similar to previous with with alignas
usage.
private:
alignas(size_t) uint8_t _ow_buf[sizeof(OneWireNg_CurrentPlatform)];
bool _srch_done;
OneWireNg *_ow;
I changed line 69 back to _ow = new (_ow_buf) OneWireNg_CurrentPlatform(
, and then tried each of your two alternatives. Each of them worked.
Cool, I'll push new version with the 2nd alt. (as more generic one) to fix this issue. Thanks for reporting this problem.
Happy to help! Thanks for your quick response and updated version.
Thanks for using the lib and constructive feedback.
Fixed by #16 (already merged to master).
Yay, it's great to see that this bug got unearthed and fixed! It's been a showstopper for SensESP ESP8266 users for quite some time but I just haven't had the time to investigate...
If I may make a kind request - could you make a new release of OneWireNg now that this issue has been fixed? TIA!
@mairas Do you confirm the resent fix works on your setups?
Tried with ESP8266, that works now. But ESP32 is broken due to the recent ESP32-C3 commit. I made a separate issue for that: #17.
I'm digressing here, but that ESP32-C3 is actually a pretty great little chip. The cheapest MCU with an integrated CAN controller you can get... I'm planning on using the bare chip in some projects. Sure, you'll need an oscillator and a flash memory, but still some pretty great peripherals at very little cost.
Working with https://github.com/SignalK/SensESP, which used the https://github.com/PaulStoffregen/OneWire library for a couple of years without issue. Recently switched to pstolarz/OneWireNg and pstolarz/Arduino-Temperature-Control-Library, and now several users are getting continuous crashes when using it with ESP8266, but not with ESP32. I've traced it down to somewhere inside the
begin(pin)
method.The first line of the error from PlatformIO (VS Code) says
Exception Cause: 9 [LoadStoreAlignmentCause: Load or store to an unaligned address]
. I noticed that the following line in thebegin(pin)
method is trying to store the newOneWireNg_CurrentPlatform
in a specific spot in memory:_ow = new (_ow_buf) OneWireNg_CurrentPlatform
I removed the
(_ow_buf)
from that line, and the crash stopped. Unfortunately, I'm away from the rest of my equipment that consumes the data from this program, so I can't test it all the way through. But could this be the cause of the crash?