So, about 2 hours ago I had working code.
I have a class, and I
was creating shapes and storing them in a vector. But I have since changed my code and can't see why I am getting a Read - Access Violation.
This is my Shapes class:
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
|
enum facing
{
UP,
RIGHT,
DOWN,
LEFT
};
class Shapes
{
public:
Shapes();
Shapes( int type, int x, int y, facing d );
~Shapes(void);
void createShape();
void setShapeType( int s ) { shapeType = s; }
void setX( int x ) { pos.X = x; }
void setY( int y ) { pos.Y = y; }
int getX() { return pos.X; }
int getY() { return pos.Y; }
void setPosition( int x, int y )
{
pos.X = x;
pos.Y = y;
}
void setFacing( facing d );
void rotate();
void move( facing d );
bool canMove( facing d );
bool canRotate( facing d );
void setColour();
void erase();
void draw();
private:
COORD pos;
COORD offset[ 4 ];
facing direction;
int shapeType;
int colour;
};
|
Here's what I had before, to create/store the class. Which was working.
1 2
|
for( int i = 0; i < 7; ++i )
shapeList.push_back( Shapes( i, 40, 3, UP ) );
|
I have since change the code to this:
Shapes *shape = new Shapes( randomRange( 0, 6 ), 40, 3, UP );
The problem I have with this, is when I check to see whether the shape can move down, or not:
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
|
bool Shapes::canMove( facing d )
{
switch( d )
{
case LEFT:
for( int i = 0; i < 4; ++i )
{
if( offset[ i ].X <= 31 )
return false;
}
break;
case DOWN:
for( int i = 0; i < 4; ++i )
{
if( offset[ i ].Y >= 47 )
return false;
}
break;
case RIGHT:
for( int i = 0; i < 4; ++i )
{
if( offset[ i ].X >= 50 )
return false;
}
break;
}
return true;
}
|
I receive the access violation on line 16.
While debugging the program, in Visual Studio, hovering the mouse over the COORD offset, Visual Studio tells me that it's unable to read the memory.
Can someone please point me in the right direction to getting this fixed! And if you need any more information/code, just ask away!
Thanks! (: