【发布时间】:2011-03-20 17:42:00
【问题描述】:
我正在使用 OpenEXR 库加载图像。
这工作正常,除了图像被旋转 180 度加载。我使用下面显示的循环来反转数组,但有时程序会退出,xcode 会给我一个 EXEC_BAD_ACCESS 错误(我认为这与 msvc 中的访问冲突相同)。它不会每次都发生,只是每 5-10 次发生一次。
理想情况下,我希望将数组反转到位,尽管这每次都会导致错误并且使用 memcpy 会失败但不会导致错误,只是一个空白图像。我想先知道是什么导致了这个问题。
这是我正在使用的代码:(Rgba 是 4 个“Half”s r、g、b 和 a 的结构,在 OpenEXR 中定义)
Rgba* readRgba(const char filename[], int& width, int& height){
Rgba* pixelBuffer = new Rgba[width * height];
Rgba* temp = new Rgba[width * height];
// ....EXR Loading code....
// TODO: *Sometimes* the following code results in a bad memory access error. No idea why.
// Flip the image to conform with OpenGL coordinates.
for (int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
temp[(i*width)+j] = pixelBuffer[(width*height)-(i*width)+j];
}
}
delete pixelBuffer;
return temp;
}
提前致谢!
【问题讨论】:
标签: c++ arrays access-violation openexr