这已经困扰了我将近 2 天了。我在我的类定义中有一个二维动态数组:
class Raster {
public:
int pixels[][4];
void drawTriangle(Vector2f & V1, Vector2f & V2, Vector2f & V3, PixelColor & colorA, PixelColor & colorB, PixelColor & colorC);
};
在我的绘图方法中,我有这个循环
for (int Y = maxY; Y >= minY; Y--) {
for (int X = minX; X <= maxX; X++) {
float lambda1;
float lambda2;
float lambda3;
triangle.getBarycentricCoordinate(X, Y, &lambda1, &lambda2, &lambda3);
if ((0.0f <= lambda1 && 0.0f <= lambda2 && 0.0f <= lambda3)) {
PixelColor a = lambda1 * colorA;
PixelColor b = lambda2 * colorB;
PixelColor c = lambda3 * colorC;
PixelColor interpolatedColor = a + b + c;
pixels[Y*width + X][0] = interpolatedColor.R;
pixels[Y*width + X][1] = interpolatedColor.G;
pixels[Y*width + X][2] = interpolatedColor.B;
}
}
}
谁能指出为什么它是错误的?这是错误消息:“抛出异常:写访问冲突。 这是 0x111013530C28FA2。”