在clear()或破坏向量时抛出的异常3

时间:2017-06-21 23:59:19

标签: c++ vector arduino esp8266 arduino-esp8266

描述

有时我在尝试清除()std :: vector时会遇到异常3。

硬件

  • 硬件:ESP-07S
  • ESP8266-Arduino库核心版本:2.4.0-rc1

IDE中的设置

  • 模块:通用ESP8266模块
  • Flash尺寸:4MB
  • CPU频率:160Mhz
  • Flash模式:qio
  • 闪光频率:40Mhz
  • 使用上传:OTA / SERIAL
  • 重置方法:ck

堆栈跟踪

这是来自Arduino的异常解码器的堆栈跟踪:

Exception 3: LoadStoreError: Processor internal physical address or data error during load or store
Decoding 30 results
0x401000b7: umm_disconnect_from_free_list at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1151
0x4021e9bc: memmove at /Users/igrokhotkov/e/newlib-xtensa/xtensa-lx106-elf/newlib/libc/string/../../../.././newlib/libc/string/memmove.c line 69 (discriminator 1)
0x40217464: Print::write(unsigned char const*, unsigned int) at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/Print.cpp line 38
0x4010020c: _umm_free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x4010068c: free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x40215b04: operator delete(void*) at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/abi.cpp line 57
0x40207940: std::_Vector_base   >::_M_deallocate(double*, unsigned int) at C:\Users\Defozo\Documents\Arduino\jeszcze nowsza wersja laser_na_stacje_v2\laser_na_stacje_v2/laser_na_stacje_v2.ino line 565
0x402088ac: std::_Vector_base   >::~_Vector_base() at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 161
0x40209748: std::vector   >::_M_erase_at_end(double*) at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 1353
:  (inlined by) std::vector   >::clear() at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 1126
:  (inlined by) loop at C:\Users\Defozo\Documents\Arduino\jeszcze nowsza wersja laser_na_stacje_v2\laser_na_stacje_v2/laser_na_stacje_v2.ino line 412
0x40217082: std::default_delete ::operator()(TransportTraits*) const at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/unique_ptr.h line 68
0x4010020c: _umm_free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x401020ea: wDev_ProcessFiq at ?? line ?
0x40215d84: loop_wrapper at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/core_esp8266_main.cpp line 124
0x4010070c: cont_norm at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/cont.S line 109

这是重置原因:

Hardware Watchdog
Fatal exception:4 flag:1 (WDT) epc1:0x40000f83 epc2:0x00000000 epc3:0x4000dd3b excvaddr:0x40023c5c depc:0x00000000

代码

我正在初始化这样的矢量:

std::vector<double> dhtTempVector, dhtHumidityVector;
std::vector<double> dhtTempMedianVector, dhtHumidityMedianVector;
std::vector<double> bmpTempVector, bmpPressureVector;
std::vector<double> bmpTempMedianVector, bmpPressureMedianVector;
dhtTempVector.reserve(5);
dhtHumidityVector.reserve(5);
bmpTempVector.reserve(5);
bmpPressureVector.reserve(5);
dhtTempMedianVector.reserve(6);
dhtHumidityMedianVector.reserve(6);
bmpPressureMedianVector.reserve(6);
bmpTempMedianVector.reserve(6);

插入类似的新值:

if (!isnan(temp) && !isnan(hum)) {
    dhtTempVector.push_back(temp);
    dhtHumidityVector.push_back(hum);
}

if (!dhtTempVector.empty()) {
    dhtTempMedianVector.push_back(median(dhtTempVector));
    dhtTempVector.clear();
}
if (!dhtHumidityVector.empty()) {
    dhtHumidityMedianVector.push_back(median(dhtHumidityVector));
    dhtHumidityVector.clear(); //line number 412
}

这是中位函数:

double median(std::vector<double> v)
{
    size_t n = v.size() / 2;
    std::nth_element(v.begin(), v.begin()+n, v.end());
    double vn = v[n];
    if(v.size()%2 == 1) {
        return vn;
    } else  {
        std::nth_element(v.begin(), v.begin()+n-1, v.end());
        return 0.5*(vn+v[n-1]);
    }
}

其他调试信息

这是一个结果:

dhtTempVector size: 4
dhtTempMedianVector size: 5
dhtHumidityVector size: 4
dhtHumidityMedianVector size: 5
29.00 29.00 29.00 29.00 --
28.70 28.75 28.80 28.90 28.90 --
41.20 41.30 41.80 41.40 --
42.65 42.55 41.80 42.30 41.75 --

这些代码行:

Serial.print("dhtTempVector size: ");
Serial.println(dhtTempVector.size());
Serial.print("dhtTempMedianVector size: ");
Serial.println(dhtTempMedianVector.size());
Serial.print("dhtHumidityVector size: ");
Serial.println(dhtHumidityVector.size());
Serial.print("dhtHumidityMedianVector size: ");
Serial.println(dhtHumidityMedianVector.size());
for (int k = 0; k < dhtTempVector.size(); ++k) {
    Serial.print(dhtTempVector.at(k));
    Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtTempMedianVector.size(); ++k) {
    Serial.print(dhtTempMedianVector.at(k));
    Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtHumidityVector.size(); ++k) {
    Serial.print(dhtHumidityVector.at(k));
    Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtHumidityMedianVector.size(); ++k) {
    Serial.print(dhtHumidityMedianVector.at(k));
    Serial.print(" ");
}
Serial.println("--");

在抛出异常之前。

摘要

看起来在清除向量期间抛出了异常。我想我也经历了在loop()函数结束时抛出的异常 - 所以当向量的析构函数被触发时。我认为这是破坏向量元素的问题,但它们只是双数。

可能是什么问题?

@Edit

我正在使用的 Arduino-ESP8266库可在此处获取: https://github.com/esp8266

这是 umm_malloc.c https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c

Print.cpp https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/Print.cpp

cont.S https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/cont.S

来自umm_malloc.c的特定

1151:

UMM_NFREE(UMM_PFREE(c)) = UMM_NFREE(c);

https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1151

1287:

if( UMM_NBLOCK(UMM_PBLOCK(c)) & UMM_FREELIST_MASK ) {

https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1287

1733:

void umm_free( void *ptr ) {

  ptr = GET_UNPOISONED(ptr);

  /* check poison of each blocks, if poisoning is enabled */
  if (!CHECK_POISON_ALL_BLOCKS()) {
    return;
  }

  /* check full integrity of the heap, if this check is enabled */
  if (!INTEGRITY_CHECK()) {
    return;
  }

  _umm_free( ptr );
} //1733

https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1733

来自Print.cpp的特定

size_t Print::write(const uint8_t *buffer, size_t size) {
    size_t n = 0;
    while(size--) {
        n += write(*buffer++); //line number 38
    }
    return n;
}

https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/Print.cpp#L38

core_esp8266_main.cpp中的特定

static void loop_wrapper() {
    static bool setup_done = false;
    preloop_update_frequency();
    if(!setup_done) {
        setup();
#ifdef DEBUG_ESP_PORT
        DEBUG_ESP_PORT.setDebugOutput(true);
#endif
        setup_done = true;
    }
    loop();
    run_scheduled_functions(); //line number 124
    esp_schedule();
}

来自cont.S的行号109:

https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/cont.S#L109

0 个答案:

没有答案