2015-04-07 36 views
0

我在qgis 2.8.1((使用qwt6的32位版本)我的插件中使用qwt5)。當我運行我的C++程序時,它崩潰與此錯誤:崩潰:這可能是由於堆的腐敗

enter image description here

問題發生在這個函數(在調試運行):

QwtPlotItemIterator it = list.begin(); 
while (it != list.end()) 
{ 
    QwtPlotItem *item = *it; 
    ++it; // increment before removing item from the list 
    item->attach(NULL); 
    delete item; 
} 

//delete all the items attached to QwtPlot 
const QwtPlotItemList &list = m_pPlot->itemList(); 
qDeleteAll(list.begin(), list.end()); 

我換成這個功能

但在這個指令再次出現死機一樣:

delete item; 

請,你有沒有對這個問題的想法?

+0

輸出窗口可能有更多診斷信息。 HEAP [qgis-bin.exe]:指定給RtlFreeHeap的無效地址(02D20000,123B6D10) Windows在qgis-bin.exe中觸發了一個斷點。 這可能是由於堆損壞引起的,這表明qgis-bin.exe或任何已加載的DLL中存在錯誤。 這也可能是由於用戶在qgis-bin.exe具有焦點時按下F12。 –

回答

-2

移動delete item以外的循環。現在您多次刪除item

+0

這就是要點。他試圖遍歷所有的指針並刪除它們。 – LawfulEvil

3

Qwt User's Guide

A QwtPlotItemList of all attached plot items.

Use caution when iterating these lists, as removing/detaching an item will invalidate the iterator. Instead you can place pointers to objects to be removed in a removal list, and traverse that list later.

重點煤礦。

+0

感謝您的回覆,我認爲這條消息(指定給RtlFreeHeap(02D20000,123B6D10)的無效地址)是一個普遍錯誤,也許它與內存管理有關,並且這是崩潰後的callstack位置:(ntdll。 dll!77e70574())。任何人都可以給我提示這可能是什麼,或者爲什麼會發生這種事故?或者任何建議,我如何才能找出問題的根源? –