为什么当我尝试运行它时我的程序崩溃

why does my program crash when i attempt to run this?

本文关键字:我的 程序 崩溃 试运行 为什么      更新时间:2023-10-16

可能的重复项:
我需要帮助声明一个 temarary 数组来容纳位图图片,同时将它旋转 90 度

为什么当我尝试运行它时我的程序崩溃?同样在第 10(+ (image.infoHeader.biWidth-c-1(的末尾;)的代码没有按照我想要的方式工作;你看出它有什么问题吗?

void rotate90(Image& image)
{
    Pixel * tempPixel = new Pixel[(image.infoHeader.biWidth * image.infoHeader.biHeight)];
    for(int r = 0; r < image.infoHeader.biHeight; r ++)
    {
        for(int c = 0; c < image.infoHeader.biWidth; c++)
        {
            int f = c+(r*image.infoHeader.biWidth);
            int t = (image.infoHeader.biHeight - r - 1) + (image.infoHeader.biWidth-c-1);
            tempPixel[t] = image.pixels[f];
        }
    }
    tempPixel = image.pixels;
    delete[] tempPixel;
}

这是一个问题:

tempPixel = image.pixels;
delete[] tempPixel;

您用不同的地址覆盖从new获得的指针。然后,在指针上调用delete[],该指针现在指向image对象拥有的内存。

相关文章: