3 Replies - 650 Views - Last Post: 21 May 2009 - 11:14 AM Rate Topic: -----

#1 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 998
  • Joined: 30-July 08

New problem

Posted 20 May 2009 - 04:09 PM

New problem with my code, it so much code I do not know what to show.

Quote

Unhandled exception at 0x004137d6 in openGL.exe: 0xC0000005: Access violation reading location 0xccccccd0.


This is the class where the problem is showing
class Tile
{
	public:
		Tile();
		Tile(unsigned int ground);
		virtual ~Tile();
		void clear();
		void setGround(unsigned int ground) { this->ground = ground; } 
		unsigned int getGround() { return ground; } // something wrong here!
	protected:
		unsigned int ground;
};


It's used ni this function that also display the problem
void Core::render_screen()
{
/* .......... */
	Tile *tiles[20][20];
	Tile *objs[20][20];
	Tile *pPlayer[20][20];
	Tile *walls[20][20];
/* ......... */
	if (tiles[x][y]) 
	{ 
		render->texture(x * 32, y * 32, pPlayer[x][y]->getGround());
		render->texture(x * 32, y * 32, objs[x][y]->getGround());
		render->texture(x * 32, y * 32, walls[x][y]->getGround());
		render->texture(x * 32, y * 32, tiles[x][y]->getGround());
	}
/* .........*/
}
Inside the if(tiles[x][y]) is where the current problem is pointing.

The debugger say this:

Quote

Lots of stuff loaded and unloaded...
'openGL.exe': Unloaded 'C:\WINDOWS\system32\mcd32.dll'
First-chance exception at 0x004137d6 in openGL.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x004137d6 in openGL.exe: 0xC0000005: Access violation reading location 0xccccccd0.
I am willing to send the entire project to someone that want to take a look but only to a person that can show that he know what he talks about (for obvious reasons).

Is This A Good Question/Topic? 0
  • +

Replies To: New problem

#2 xtreampb  Icon User is offline

  • D.I.C Regular

Reputation: 14
  • View blog
  • Posts: 337
  • Joined: 20-June 07

Re: New problem

Posted 20 May 2009 - 08:48 PM

alright
where you are returning ground, don't insert
return ground



until you are in you .cpp file. i looks like in your first code block you are in the header file for your tile class. remove the return ground from the header file and insert it in the .cpp file of your tile class where you want to return ground
Was This Post Helpful? 0
  • +
  • -

#3 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,195
  • Joined: 14-February 08

Re: New problem

Posted 21 May 2009 - 11:05 AM

@xstreampb

Its perfectly acceptable to include a small function declaration and implementation in the header file, especially if it is something small like a return value.

I myself wouldn't do it but it wouldn't cause any problems really.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,195
  • Joined: 14-February 08

Re: New problem

Posted 21 May 2009 - 11:14 AM

@FrozenSnake

I think your problem could be that you are trying to access objects outside of their scope
 render->texture(x * 32, y * 32, pPlayer[x][y]->getGround());



when you write pPlayer[x][y]->getGround()); maybe pPlayer doesn't exist in this scope same with the other values.

To get around this I think your going to have to create a static pPlayer or go down the singleton route. This would mean that including the .h of player would give you access to this object.

After doing this your code would look something like this
render->texture(x * 32, y * 32, Player::pPlayer[x][y]->getGround());



I would need to see some more of your code to determine whether this is the problem or not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1