esphome / esphome/issues

ESP8266 - Restoring global variable of type std::vector<std::string> from flash causing bootloop

Open
#2,685 10 comments 0 reactions 0 assignees View on GitHub
component: globals Project: Documentation
Dominant language
No language data
Stars
313
Forks
40
PR merge metrics
No merged PRs in 30d

Description

### The problem

Hello, I just found bug when restoring saved variable of type std::vector

When variable is set to restore: false no bootloop is present.
Program is crashing at last line in lambda:
`id(tag_list) = result;`

I tried clearing existing variable and assigning new values into it but it's crashing too:
```
std::stringstream data(x);
std::string line;

id(tag_list).clear();
while(std::getline(data,line,',')) {
ESP_LOGD("main", "Inserting card %s", line.c_str());
id(tag_list).push_back(line);
}
```

Attached minimal YAML for easy reproduction.

Test data for sensor:
`97-C3-C9-1C,97-C3-C9-1A,97-C3-C9-1B,97-C3-C9-1Y,97-C3-C9-1X,97-C3-C9-1E`

### Which version of ESPHome has the issue?

v2021.10.3

### What type of installation are you using?

Home Assistant Add-on

### Which version of Home Assistant has the issue?

_No response_

### What platform are you using?

ESP8266

### Board

nodemcu

### Component causing the issue

_No response_

### Example YAML snippet

```yaml
esphome:
platform: ESP8266
board: nodemcuv2
esp8266_restore_from_flash: true
includes:
- sstream.h

globals:
- id: tag_list
type: std::vector
restore_value: true

text_sensor:
- platform: homeassistant
id: allowed_tags
entity_id: sensor.allowed_tags
on_value:
then:
- lambda: |-
std::vector result;
std::stringstream data(x);
std::string line;

while(std::getline(data,line,',')) {
ESP_LOGD("main", "Inserting card %s", line.c_str());
result.push_back(line);
}

id(tag_list) = result;
```

### Anything in the logs that might be useful for us?

_No response_

### Additional information

Log from serial:

```
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x40232e88 epc2=0x00000000 epc3=0x4021c736 excvaddr=0xfffffffd depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffa20 end: 3fffffc0 offset: 0190
3ffffbb0: 4021089c 3ffe8da6 3ffffcf8 4022c40b
3ffffbc0: 3ffffc10 3ffffc00 00000010 4023373e
3ffffbd0: 00000000 ffffffff 0000000b 4022c40b
3ffffbe0: 4021089c 00000006 3fff29cc 40233758
3ffffbf0: 3ffffc00 3ffffc00 00000010 402118d4
3ffffc00: 3fff16cc 3fff488c 0000000b 3ffffe5c
3ffffc10: 3fff48c0 39432d33 3ffffcec 3ffffe5c
3ffffc20: 4021089c 3ffe8da6 3ffffcf8 40211e1c
3ffffc30: 4021fe2c 00000000 4021fe40 4021fde8
3ffffc40: 3fff4788 3fff47cf 3fff47cf 3fff4788
3ffffc50: 3fff4788 3fff47cf 3fff0b44 00000018
3ffffc60: 3fff4788 4021fe54 00000006 00000000
3ffffc70: 00001002 00000000 00000006 00000000
3ffffc80: 00000000 00000000 00000000 00000000
3ffffc90: 00000000 00000000 00000000 00000000
3ffffca0: 00000000 00000000 00000000 00000000
3ffffcb0: 00000000 00000000 00000000 00000000
3ffffcc0: 00000000 00000000 00000008 3ffffc88
3ffffcd0: 3fff0b44 00000000 3fff0000 3ffffc3c
3ffffce0: 3fff0820 3fff07f8 3fff0800 3fff488c
3ffffcf0: 3fff48a4 3fff48ac 3fff48c0 3fff36b0
3ffffd00: 00000005 3ffffd50 3fff2e6c 402108c8
3ffffd10: 3ffefd8c 3ffefd8c 00000019 40206d71
3ffffd20: 3fff132c 00000011 3fff2e6c 40210838
3ffffd30: 3fff36b0 3ffffe10 3fff255c 4020ff8c
3ffffd40: 3ffffdb0 40210810 3fff2e6c 40211f57
3ffffd50: 3fff36b0 00000011 00000015 4020ffb8
3ffffd60: 3ffffd90 3fff25cc 3fff25d4 40212028
3ffffd70: 3fff36b0 3fff36b0 3fff36b0 4023373e
3ffffd80: 3ffffdd0 3ffffdc0 3fff25bc 4020af68
3ffffd90: 3fff36b0 3ffefd8c 3fff255c 40233758
3ffffda0: 3ffffe54 3ffffe10 3fff255c 4020afcb
3ffffdb0: 3fff36b0 3fff255c 3ffffe10 40233758
3ffffdc0: 3ffffe54 3fff255c 3ffffe10 4020b010
3ffffdd0: 3fff36b0 3fff36b0 00000048 40209cd2
3ffffde0: 3fff45ca 3fff4064 3ffffe10 40206988
3ffffdf0: 3fff45ac 3ffffe50 00000065 40205675
3ffffe00: 00000001 3fff406c 3ffffe50 40201f2e
3ffffe10: 3fff36b0 3ffefd8c 00000001 00000000
3ffffe20: 3fff4088 00000047 000032b5 3fff3658
3ffffe30: 00000000 00000000 4bc6a7f0 3fff3658
3ffffe40: 3fff3658 00000000 3fff429c 40204ae7
3ffffe50: 4021f220 3fff4628 3fff36b0 3ffefd8c
3ffffe60: 3fff3658 00000000 3fff429c 401001a4
3ffffe70: 3fff3658 00000000 3fff429c 40201a00
3ffffe80: 0000000a 4bc6a7f0 000032b0 00000000
3ffffe90: 3fff45ac 3fff4611 3fff4611 00000028
3ffffea0: 00000000 00000065 3ffffee0 40210242
3ffffeb0: 00000000 4020ffe8 3fff331c 00000008
3ffffec0: 00000002 3fff331c 3fff11f4 3fff3658
3ffffed0: 3fff3658 3fff3658 3fff1eec 402052d6
3ffffee0: 00000000 00000000 4bc6a7f0 00000000
3ffffef0: 00000000 4bc6a7f0 000032b5 3fff1eec
3fffff00: 00000000 00000000 0000001c 00000000
3fffff10: 3fff3678 00000002 40100a8a 25a1cac0
3fffff20: 00000000 00000002 3fff1e84 3fff1eec
3fffff30: 3fff367c 00000002 3ffef580 4021e4e4
3fffff40: 3fff3601 00000009 3ffef580 4021e58d
3fffff50: 3fffdad0 00000002 3ffef580 4020e2e1
3fffff60: 000032b5 3fff1eec feefef00 feefeffe
3fffff70: 3fff3684 3ffef630 3fff2c54 3ffef638
3fffff80: 00000000 00000000 00000001 3ffefa10
3fffff90: 3fffdad0 00000000 3ffef9d0 402116cc
3fffffa0: 3fffdad0 00000000 3ffef9d0 4021b7f8
3fffffb0: feefeffe feefeffe 3ffe85c0 40100619
<<

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.