nvoglv32.dll glTexSubImage 中的 OpenGL 未处理异常
OpenGL Unhandled exception in nvoglv32.dll glTexSubImage
我发生了一次非常随机的崩溃,大约每 10 次我就会在 nvoglv32.dll
中发生一次崩溃。它并不总是发生在完全相同的地方,但它确实发生在距同一地方 10 行左右的范围内。
我添加了使用 glTexSubImage2D()
更新纹理的功能,现在我遇到了这些间歇性崩溃。
void UpdateTexture(const GLuint textureID, const CaffApp::Dev::Format format, const CaffApp::Dev::TextureD dimention, const uint32_t offsetX, const uint32_t offsetY, const uint32_t width, const uint32_t height, void *data)
{
using namespace CaffApp::Dev;
const auto externalFormat = format == Format::DEV ? GL_RGBA32F : GL_RGBA ;
const auto internalFormat = GL_RGBA;
const auto formatType = format == Format::R8G8B8 ? GL_UNSIGNED_BYTE : GL_FLOAT;
const auto glDimention = GetDimentionTarget(dimention);
assert(CaffMath::IsPOW2(texWidth));
assert(CaffMath::IsPOW2(texHeight));
glBindTexture(glDimention, textureID);
switch(glDimention)
{
case(GL_TEXTURE_1D):
{
glTexSubImage1D(GL_TEXTURE_1D, offsetX, 0, texWidth, internalFormat, formatType, data);
break;
}
case(GL_TEXTURE_2D):
{
glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, texWidth, texHeight, internalFormat, formatType, data);
break;
}
};
glBindTexture(glDimention, 0);
GL_ERROR("Updating texture.")
}
void Texture::updateSubset(const std::vector<float> &data, const uint32_t offsetX, const uint32_t offsetY)
{
assert(m_textureID);
uint32_t sizeX = m_width;
uint32_t sizeY = m_height;
if(sizeX == 0 || sizeY == 0)
{
SetTextureDimentionFromDataSize(m_dimention, data.size(), sizeX, sizeY);
}
UpdateTexture(m_textureID, m_format, m_dimention, offsetX, offsetY, sizeX, sizeY, (void*)data.data());
GL_ERROR("Updating texture.")
}
如果发生崩溃,它只会在第一次调用 glTexSubImage... 时发生。否则没关系。
我确实看到了一些关于顶点属性设置不正确的事情,但我真的看不出有什么不对,而且那是代码在 2 年左右的时间里没有改变过,所以想想它在这里。
有什么想法吗?
无论 data
指向什么,您都可能越界访问。如果对齐方式和步幅设置不正确,就会发生这种情况。如果数据分配给 short,也会发生这种情况;它不必在第一件事越界时立即崩溃,它可以污染地址 space 并在其他地方触发崩溃。
我发生了一次非常随机的崩溃,大约每 10 次我就会在 nvoglv32.dll
中发生一次崩溃。它并不总是发生在完全相同的地方,但它确实发生在距同一地方 10 行左右的范围内。
我添加了使用 glTexSubImage2D()
更新纹理的功能,现在我遇到了这些间歇性崩溃。
void UpdateTexture(const GLuint textureID, const CaffApp::Dev::Format format, const CaffApp::Dev::TextureD dimention, const uint32_t offsetX, const uint32_t offsetY, const uint32_t width, const uint32_t height, void *data)
{
using namespace CaffApp::Dev;
const auto externalFormat = format == Format::DEV ? GL_RGBA32F : GL_RGBA ;
const auto internalFormat = GL_RGBA;
const auto formatType = format == Format::R8G8B8 ? GL_UNSIGNED_BYTE : GL_FLOAT;
const auto glDimention = GetDimentionTarget(dimention);
assert(CaffMath::IsPOW2(texWidth));
assert(CaffMath::IsPOW2(texHeight));
glBindTexture(glDimention, textureID);
switch(glDimention)
{
case(GL_TEXTURE_1D):
{
glTexSubImage1D(GL_TEXTURE_1D, offsetX, 0, texWidth, internalFormat, formatType, data);
break;
}
case(GL_TEXTURE_2D):
{
glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, texWidth, texHeight, internalFormat, formatType, data);
break;
}
};
glBindTexture(glDimention, 0);
GL_ERROR("Updating texture.")
}
void Texture::updateSubset(const std::vector<float> &data, const uint32_t offsetX, const uint32_t offsetY)
{
assert(m_textureID);
uint32_t sizeX = m_width;
uint32_t sizeY = m_height;
if(sizeX == 0 || sizeY == 0)
{
SetTextureDimentionFromDataSize(m_dimention, data.size(), sizeX, sizeY);
}
UpdateTexture(m_textureID, m_format, m_dimention, offsetX, offsetY, sizeX, sizeY, (void*)data.data());
GL_ERROR("Updating texture.")
}
如果发生崩溃,它只会在第一次调用 glTexSubImage... 时发生。否则没关系。
我确实看到了一些关于顶点属性设置不正确的事情,但我真的看不出有什么不对,而且那是代码在 2 年左右的时间里没有改变过,所以想想它在这里。
有什么想法吗?
无论 data
指向什么,您都可能越界访问。如果对齐方式和步幅设置不正确,就会发生这种情况。如果数据分配给 short,也会发生这种情况;它不必在第一件事越界时立即崩溃,它可以污染地址 space 并在其他地方触发崩溃。