Don't understand this error message
Apr 25, 2010 at 7:24am UTC
My program compiles fine but when I run it I get this:
Unhandled exception at 0x000000ff in mkeasal_proj6.exe: 0xC0000005: Access violation reading location 0x000000ff.
And when I debug and do a break it says it can't and just gives me the disassembly code which points to the 000000ff location. Anyone know why this might happen? Here is my code, maybe my arrays are going out of bounds? I know it has something to do with my functions because if I comment both of them out it works fine but if even one is not commented out it gives me that error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
#include <iostream>
#include <string>
#include <cassert>
#include <fstream>
using namespace std;
// This struct holds the information for a single pixel color
struct pixelType
{
short int redVal;
short int greenVal;
short int blueVal;
};
struct rectangle
{
int height ;
int width ;
};
void squareColor(string color, int startPR, int startPC, int size);
void backgroundColor(string color);
const int NUM_ROWS = 300;
const int NUM_COLS = 400;
const int MAXVAL = 255;
pixelType image[NUM_ROWS][NUM_COLS];
int main()
{
string shapeType;
string name = "P3" ;
string bgColor;
string sColor;
string shape;
int startPR;
int startPC;
int size;
char fileName[MAXVAL];
ifstream inFile;
ofstream outFile;
inFile.open("imageInput.txt" );
inFile >> fileName;
inFile >> bgColor;
inFile >> shape >> sColor >> startPR >> startPC >> size;
backgroundColor(bgColor);
if (shape == "square" )
{
squareColor(sColor, startPR, startPC, size);
}
outFile.open(fileName);
outFile << name << endl;
outFile << NUM_COLS << " " << NUM_ROWS << endl;
outFile << MAXVAL << endl;
for (int r = 0; r < NUM_ROWS; r++)
{
for (int c = 0; c < NUM_COLS; c++)
{
outFile << image[r][c].redVal << " " << image[r][c].greenVal << " " << image[r][c].blueVal << " " ;
}
}
inFile.close();
outFile.close();
return (0);
}
void squareColor(
string color, int startPR, int startPC, int size)
{
if (color == "red" )
{
for (int r = startPR; r < (startPR + size); r++)
{
for (int c = startPC; r < (startPC + size); c++)
{
image[r][c].redVal = 255;
image[r][c].greenVal = 0;
image[r][c].blueVal = 0;
}
}
}
if (color == "blue" )
{
for (int r = startPR; r < (startPR + size); r++)
{
for (int c = startPC; r < (startPC + size); c++)
{
image[r][c].redVal = 0;
image[r][c].greenVal = 0;
image[r][c].blueVal = 255;
}
}
}
}
void backgroundColor(string color)
{
if (color == "red" )
{
for (int r = 0; r < NUM_ROWS; r++)
{
for (int c = 0; r < NUM_COLS; c++)
{
image[r][c].redVal = 255;
image[r][c].greenVal = 0;
image[r][c].blueVal = 0;
}
}
}
if (color == "blue" )
{
for (int r = 0; r < NUM_ROWS; r++)
{
for (int c = 0; r < NUM_COLS; c++)
{
image[r][c].redVal = 0;
image[r][c].greenVal = 0;
image[r][c].blueVal = 255;
}
}
}
}
Thanks for any help or suggestions.
Last edited on Apr 25, 2010 at 7:36am UTC
Apr 25, 2010 at 10:58am UTC
it's working fine except for (int c = startPC; r < (startPC + size); c++)
which is an infinite loop. it happen many times in your code. hope that helps
Apr 25, 2010 at 3:29pm UTC
Oh yeah, you're right. Thanks. Copy and paste isn't you're friend if you're not paying attention!
Topic archived. No new replies allowed.