简体   繁体   English

glMapBufferRange在Android GLES应用程序上崩溃

[英]glMapBufferRange crashing on Android GLES app

I am trying to morph some vertices on a GLES application on android and glMapBufferRange keeps crashing with the following error: 我试图在android上的GLES应用程序上变形一些顶点,glMapBufferRange不断崩溃,出现以下错误:

SIGSEGV (signal SIGSEGV: address access protected (fault address: 0xef13d664)) SIGSEGV(信号SIGSEGV:地址访问受保护(故障地址:0xef13d664))

I more or less followed the example of this web-site: 我或多或少地遵循了这个网站的例子:

http://www.songho.ca/opengl/gl_vbo.html#update http://www.songho.ca/opengl/gl_vbo.html#update

but not sure if I am missing something. 但不确定我是否遗漏了什么。

I created my VBOs at initialization time and I can draw the object with no issues. 我在初始化时创建了VBO,我可以毫无问题地绘制对象。 The code of creation goes: 创作代码如下:

void SubObject3D::CreateVBO(VBOInfo &vboInfoIn) {
    // m_vboIds[0] - used to store vertex attribute data
    // m_vboIds[l] - used to store element indices
    glGenBuffers(2, vboInfoIn.vboIds);

    // Let the buffer all dynamic for morphing
    glBindBuffer(GL_ARRAY_BUFFER, vboInfoIn.vboIds[0]);
    glBufferData(GL_ARRAY_BUFFER,
                 (GLsizeiptr) (vboInfoIn.vertexStride * vboInfoIn.verticesCount),
                 vboInfoIn.pVertices, GL_DYNAMIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboInfoIn.vboIds[1]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                 (GLsizeiptr) (sizeof(GLushort) * vboInfoIn.indicesCount),
                 vboInfoIn.pIndices, GL_STATIC_DRAW);
}

struct VBOInfo {
    VBOInfo() {
        memset(this, 0x00, sizeof(VBOInfo));
        vboIds[0] = 0xdeadbeef;
        vboIds[1] = 0xdeadbeef;
    }

    // VertexBufferObject Ids
    GLuint vboIds[2];

    // Points to the source data
    GLfloat *pVertices;         // Pointer of original data
    GLuint verticesCount;
    GLushort *pIndices;         // Pointer of original data
    GLuint indicesCount;

    GLint vertexStride;
};

then later in the Rendering loop I tried to get the hold of my vertex pointer as such: 然后在渲染循环中,我试图抓住我的顶点指针,如下所示:

// I stored the information at creation time here:
VBOInfo mVBOGeometryInfo;
//later I call here to get the pointer
GLfloat *SubObject3D::MapVBO() {
    GLfloat *pVertices = nullptr;

    glBindBuffer(GL_ARRAY_BUFFER, mVBOGeometryInfo.vboIds[0]);

    GLsizeiptr length = (GLsizeiptr) (mVBOGeometryInfo.vertexStride *
                                      mVBOGeometryInfo.verticesCount);
    pVertices = (GLfloat *) glMapBufferRange(
            GL_ARRAY_BUFFER, 0,
            length,
            GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT
    );

    if (pVertices == nullptr) {
        LOGE ("Could not map VBO");
    }
    return pVertices;
}

but it crashed right at glMapBufferRange. 但它在glMapBufferRange上崩溃了。

This is an android application that uses NDK. 这是一个使用NDK的Android应用程序。 The hardware is a Samsung S6 phone. 硬件是三星S6手机。

thx! 谢谢!

This was quite painful to resolve this issue, but there is no problem with the code above per se. 解决此问题非常痛苦,但上面的代码本身没有问题。 It was basically the include. 它基本上是包括。 My code was based off the google sample "more teapots" located here: 我的代码基于谷歌样本“更多茶壶”位于此处:

https://github.com/googlesamples/android-ndk/tree/master/teapots https://github.com/googlesamples/android-ndk/tree/master/teapots

I had to follow their pattern and change my include to GLES from: 我必须遵循他们的模式并将我的包含更改为GLES:

#include <GLES3/gl3.h>

to use their stubs: 使用他们的存根:

#include "gl3stub.h"

why? 为什么? I don't know, but likely causing the linker to link incorrect code. 我不知道,但可能导致链接器链接错误的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM