C 矢量push_back访问违规

c++ vector push_back access violation

本文关键字:访问 back 矢量 push      更新时间:2023-10-16

我在使用std :: vector时遇到随机例外。

这是主要元素:

struct Stroke
{
    std::vector<vec2>   points;
    Pixel color;
    std::vector<unsigned int> pixelIds;
};
void myFunc()
{
    while (strokes.size() < 5000)
    {
        if (/*A condition that is always met at some point*/)
        {
            break;
        }
        //Some code
        newStroke->pixelIds.clear();
        newStroke->pixelIds.resize(0);
        strokes.push_back(newStroke);
    }

    for (int i = 0; i < strokes.size(); ++i)
    {
        drawStroke(strokes[i]);
    }
}

void drawStroke(Stroke * currentStroke)
{
    std::vector<int> roundIds;
    //Fill roundIds
    //Some loops and conditions
    for (int i = 0; i < roundIds.size(); ++i)
    {
        if (/*Check condition*/)
        {
            // Exception is raised deeper in the stack here
            currentStroke->pixelIds.push_back(currentRoundId);
        }
    }
}

我忽略了代码的大部分,这些部分不应该真正影响这一点,因为我不知道问题可能来自何处(所以我必须复制/粘贴整个代码:D)。在最后一行中,我在堆栈中随机更深入访问违规(_orphan_range std :: vector的方法)。

我在手表中没有看到弯曲式的任何问题,要点向量看起来很正常,颜色也是颜色,我想某些像素的内部值被损坏了(_myfirst = 0x000000000000000038c700 _myEnd = 0x00000000000000000000000000000000000000000000000000000000000000000000 c不太好我,但我不确定)。

我对STL的细节不是很有经验,我不知道要寻找什么与向量的内部值混乱。

任何建议或建议将不胜感激!谢谢!

myfunct具有一个无尽的循环,可以填充stoke vector,直到您离开内存。