0

When I filter to reflect an image, it keeps printing the following without stopping:

UndefinedBehaviorSanitizer:DEADLYSIGNAL UndefinedBehaviorSanitizer:DEADLYSIGNAL UndefinedBehaviorSanitizer:DEADLYSIGNAL UndefinedBehaviorSanitizer:DEADLYSIGNAL UndefinedBehaviorSanitizer:DEADLYSIGNAL

until I hit ctrl+c.

Here is what my code currently looks like:

// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    // Declare a temporary variable with an array
    RGBTRIPLE temporary[width];

    // Iterate through each row of pixels
    for (int i = 0; i < width; i++)
    {
        // Allocate pixels on left half of image to temporary variable
        for (int j = 0; j < round(width / 2.0); j++)
        {
            temporary[j] = image[i][j];
        }

        // Swap pixels on left half with pixels on right half
        for (int j = 0; j < round(width / 2.0); j++)
        {
            image[i][j] = image[i][width - 1 - j];
        }

        // Swap pixels on right half with pixels on left half that were moved to temp. variable
        for (int j = round(width / 2.0); j < width; j++)
        {
            image[i][j] = temporary[width - 1 - j];
        }
    }
    // Return new color values
    return;
}

I even tried debug50 and I'm still having difficulty narrowing down where exactly my issue is. It did, however, indicate that there is a segmentation fault present.

3
for (int i = 0; i < width; i++)

Shouldn't it be height?

1

I had the exact same problem with filter in pset4 when applying the greyscale filter and this thread solved it for me.

They set up the function definition they entered the size argument as:

void grayscale(int height, int width, RGBTRIPLE image[height][width])

not

void grayscale(int height, int width, RGBTRIPLE image[width][height])

so to iterate through the pixels your first for loop (value [i]) needs to be check in terms of height and your second for loop (value [j]) needs to check width. Its a bit counter-intuitive at first, but this will scan each row top-to-bottom (each j of each i loop) rather than each column of the image left-to right.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .