Weird Seg fault

Hello, I'm getting a weird segFault.. I'm stumped on why its happening... here is some of my code

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
...

Ground * grounds[32000];

int main () {

  grounds[groundNum] = new Ground(10, 10, 20, 40);

  // Update all the grounds
  for (int i = 0; i < groundNum; i++) {

    grounds[i]->update();  

  }

}

...


ground.h
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
#ifndef __GROUND_H__
#define __GROUND_H__

class Ground {
	
	protected:

	// Position
	int x, y;

	// Size
	int xSize, ySize;

	public:

	Ground  (unsigned int X, unsigned int Y, unsigned int XSize, unsigned int YSize);
	~Ground ();

	int getX      ();
	int getY      ();
	int getXSize  ();
	int getYSize  ();

	void update ();
	
};

#endif


ground.cpp
1
2
3
4
5
6
7
8
9
...

void Ground::update () {

  App.Draw(sf::Shape::Rectangle(x, y, xSize, ySize, sf::Color(0x00, 0x00, 0xff)));

}

...


EDIT:

gdb says its coming from "App.Draw(sf::Shape::Rectangle(x, y, xSize, ySize, sf::Color(0x00, 0x00, 0xff)));" in "void Ground::update"
Last edited on
I'll take a wild guess and say that App requires some initialization code that you forgot to add before it works.
? you mean like declaring it? earlyer on I declare App as sf::RenderWindow. Also, I can draw other things on the screen, just the Ground class is being a pain... I think it's somewhere in my pointer.
Well, are all of your pointers initialized? Is groundNum set to the correct value?
Yeah, I got a hacky fix to work.

int groundNum = -1;

// Create a blank ground piece for the ground starter
grounds[groundNum] = new Ground(0, 0, 0, 0);
Topic archived. No new replies allowed.