【问题标题】:C++ atioglxx.pdb not loaded error glBufferData OpenGLC++ atioglxx.pdb 未加载错误 glBufferData OpenGL
【发布时间】:2020-11-01 17:52:52
【问题描述】:

尝试将 OBJ 文件加载到我的项目中时,我不断收到此错误

atioglxx.pdb 未加载

出现以下异常

在 Reality.exe 中的 0x53A083FF (atioglxx.dll) 处引发异常:0xC0000005:访问冲突读取位置 0x0894F000。

有时我收到此错误,有时我没有,我的模型出现在屏幕上。因此,我尝试调试代码,发现 glBufferData 函数是导致此错误的原因,但无法弄清楚它的问题所在。

这里是 OBJ 加载函数

bool Mesh::LoadOBJ(std::string objFile) 
{
    std::vector<glm::vec3> position;
    std::vector<glm::vec2> UVs;
    std::vector<glm::vec3> normals;
    std::vector< float > vertices;
    std::vector<unsigned int> indices;
    std::unordered_map< std::string, unsigned int> isProcessed;

    std::ifstream myFile;
    myFile.open(objFile);
    if (!myFile.is_open())
    {
        std::cout << "Error Openening OBJ file : " << objFile;
        return false; 
    }

    unsigned int cnt = 1;
    while (!myFile.eof())
    {
        std::string type;
        myFile >> type;
        float x, y, z;
        if (type == "v") {
            myFile >> x >> y >> z;

            glm::vec3 v(x, y, z); 
            position.push_back(v);
        }
        else if (type == "vt") {
            myFile >> x >> y;

            glm::vec2 v(x, y);
            UVs.push_back(v);
        }
        else if (type == "vn") {
            myFile >> x >> y >> z;
            glm::vec3 v(x, y, z);

            normals.push_back(v);
        }
        else if (type == "f") {
            std::string p1, p2, p3;
            std::vector<std::string> vertex(3);

            myFile >> p1;
            if (!isProcessed[p1]) {

                isProcessed[p1] = cnt;
                indices.push_back(cnt - 1);

                vertex[0] = "";
                vertex[1] = "";
                vertex[2] = "";

                int c = 0;
                for (int i = 0; i < p1.size(); ++i) {
                    if (p1[i] == '/') {
                        ++c;
                        continue;
                    }
                    vertex[c] += p1[i]; 
                }

                if (vertex[0].size() > 0) {
                    int vertexIndex = std::stoi(vertex[0]);
                    --vertexIndex;
                    vertices.push_back(position[vertexIndex].x);
                    vertices.push_back(position[vertexIndex].y);
                    vertices.push_back(position[vertexIndex].z);
                }

                if (vertex[1].size() > 0) {
                    int UVsIndex = std::stoi(vertex[1]);
                    --UVsIndex;
                    vertices.push_back(UVs[UVsIndex].x);
                    vertices.push_back(UVs[UVsIndex].y);
                }

                if (vertex[2].size() > 0) {
                    int normalIndex = std::stoi(vertex[2]);
                    --normalIndex;
                    vertices.push_back(normals[normalIndex].x);
                    vertices.push_back(normals[normalIndex].y);
                    vertices.push_back(normals[normalIndex].z);
                }

                ++cnt;

            }
            else {
                indices.push_back(isProcessed[p1] - 1);
            }

            myFile >> p2;
            if (!isProcessed[p2]) {

                isProcessed[p2] = cnt;
                indices.push_back(cnt - 1);

                vertex[0] = "";
                vertex[1] = "";
                vertex[2] = "";

                int c = 0;
                for (int i = 0; i < p2.size(); ++i) {
                    if (p2[i] == '/') {
                        ++c;
                        continue;
                    }
                    vertex[c] += p2[i];
                }

                if (vertex[0].size() > 0) {
                    int vertexIndex = std::stoi(vertex[0]);
                    --vertexIndex;
                    vertices.push_back(position[vertexIndex].x);
                    vertices.push_back(position[vertexIndex].y);
                    vertices.push_back(position[vertexIndex].z);
                }

                if (vertex[1].size() > 0) {
                    int UVsIndex = std::stoi(vertex[1]);
                    --UVsIndex;
                    vertices.push_back(UVs[UVsIndex].x);
                    vertices.push_back(UVs[UVsIndex].y);
                }

                if (vertex[2].size() > 0) {
                    int normalIndex = std::stoi(vertex[2]);
                    --normalIndex;
                    vertices.push_back(normals[normalIndex].x);
                    vertices.push_back(normals[normalIndex].y);
                    vertices.push_back(normals[normalIndex].z);
                }

                ++cnt;

            }
            else {
                indices.push_back(isProcessed[p2] - 1);
            }

            myFile >> p3;
            if (!isProcessed[p3]) {

                isProcessed[p3] = cnt;
                indices.push_back(cnt - 1);

                vertex[0] = "";
                vertex[1] = "";
                vertex[2] = "";

                int c = 0;
                for (int i = 0; i < p3.size(); ++i) {
                    if (p3[i] == '/') {
                        ++c;
                        continue;
                    }
                    vertex[c] += p3[i];
                }

                if (vertex[0].size() > 0) {
                    int vertexIndex = std::stoi(vertex[0]);
                    --vertexIndex;
                    vertices.push_back(position[vertexIndex].x);
                    vertices.push_back(position[vertexIndex].y);
                    vertices.push_back(position[vertexIndex].z);
                }

                if (vertex[1].size() > 0) {
                    int UVsIndex = std::stoi(vertex[1]);
                    --UVsIndex;
                    vertices.push_back(UVs[UVsIndex].x);
                    vertices.push_back(UVs[UVsIndex].y);
                }

                if (vertex[2].size() > 0) {
                    int normalIndex = std::stoi(vertex[2]);
                    --normalIndex;
                    vertices.push_back(normals[normalIndex].x);
                    vertices.push_back(normals[normalIndex].y);
                    vertices.push_back(normals[normalIndex].z);
                }

                ++cnt;

            }
            else {
                indices.push_back(isProcessed[p3] - 1);
            }
        }

    mVAO = new VertexArrayObject(vertices , vertices.size() , indices , static_cast<unsigned int>(indices.size())); 
    myFile.close();
    return true ; 

这是我的 VertexArray 类的构造函数

VertexArrayObject::VertexArrayObject(std::vector<float>& vertices, int VBOsize, std::vector<unsigned int>& indecies, unsigned int EBOsize):
    EBOsize(EBOsize)
{

    glGenVertexArrays(1, &mVAOiD);
    glBindVertexArray(mVAOiD);

    glGenBuffers(1, &mVBOiD);
    glBindBuffer(GL_ARRAY_BUFFER, mVBOiD);
    glBufferData(GL_ARRAY_BUFFER, 8 * VBOsize * sizeof(float) , &vertices[0], GL_STATIC_DRAW);

    glGenBuffers(1, &mEBOiD);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mEBOiD);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, EBOsize * sizeof(unsigned int), &indecies[0], GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), 0);

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), reinterpret_cast<void*>(sizeof(float) * 3));

    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), reinterpret_cast<void*>(sizeof(float) * 5));
}

这是我要渲染的模型的 OBJ 文件 Rock.obj

注意 这是我关于stackoverflow的第一个问题,所以请放轻松。

【问题讨论】:

  • atioglxx.pdb not loaded 不是错误或问题。您的图形驱动程序没有提供调试符号以允许您单步执行 GPU 驱动程序。即使这是可用的,您也不应该需要或想要它。你不会想为他们调试 AMD 的代码。

标签: c++ opengl c++14 glm-math opengl-3


【解决方案1】:

以字节为单位的缓冲区大小的计算是错误的。 verizes.size()不是顶点属性的个数,是std::vectorfloat元素的个数。

您将vertices.size() 传递给VertexArrayObjects 构造函数的参数VBOsize

mVAO = new VertexArrayObject(vertices , vertices.size(), indices ,static_cast<unsigned int>(indices.size()));

在构造函数中VBOsize乘以8:

VertexArrayObject::VertexArrayObject(std::vector<float>& vertices, int VBOsize, std::vector<unsigned int>& indecies, unsigned int EBOsize)
   :EBOsize(EBOsize)
{
   // [...]

   glBufferData(GL_ARRAY_BUFFER, 8 * VBOsize * sizeof(float) , &vertices[0], GL_STATIC_DRAW);
   // [...]

如果VBOsize是顶点的数量,那么你必须将vertices.size()除以8:

mVAO = new VertexArrayObject(vertices, vertices.size() , indices , static_cast&lt;unsigned int&gt;(indices.size()));

mVAO = new VertexArrayObject(vertices, vertices.size() / 8, indices, static_cast<unsigned int>(indices.size())); 

无论如何,我建议更改缓冲区大小的计算:

glBufferData(GL_ARRAY_BUFFER, 8 * VBOsize * sizeof(float) , &amp;vertices[0], GL_STATIC_DRAW);

glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);

【讨论】:

    猜你喜欢
    • 2012-05-27
    • 2014-08-04
    • 2020-01-28
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多