Skip to main content
deleted 633 characters in body
Source Link
PeterT
  • 626
  • 6
  • 8

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

edit:

Another problem is right here:

  b2PolygonShape platformShape;  //creates a b2PolygonShape
  platformShape.SetAsBox(hx, hy);//modifies it
  b2FixtureDef platformFixture;  //creates a definition object
  platformFixture.shape = &platformShape;// saves a pointer to a local object (potentially dangerous, try not to do this)
  platform->CreateFixture(&platformFixture);// copies the information from the local b2FixtureDef
  bbox = platform;
}//here every local object gets destroyed including platformShape (not OK, you still have a pointer to it) and platformFixture (ok to destroy)

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

edit:

Another problem is right here:

  b2PolygonShape platformShape;  //creates a b2PolygonShape
  platformShape.SetAsBox(hx, hy);//modifies it
  b2FixtureDef platformFixture;  //creates a definition object
  platformFixture.shape = &platformShape;// saves a pointer to a local object (potentially dangerous, try not to do this)
  platform->CreateFixture(&platformFixture);// copies the information from the local b2FixtureDef
  bbox = platform;
}//here every local object gets destroyed including platformShape (not OK, you still have a pointer to it) and platformFixture (ok to destroy)

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

added 637 characters in body
Source Link
PeterT
  • 626
  • 6
  • 8

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

edit:

Another problem is right here:

  b2PolygonShape platformShape;  //creates a b2PolygonShape
  platformShape.SetAsBox(hx, hy);//modifies it
  b2FixtureDef platformFixture;  //creates a definition object
  platformFixture.shape = &platformShape;// saves a pointer to a local object (potentially dangerous, try not to do this)
  platform->CreateFixture(&platformFixture);// copies the information from the local b2FixtureDef
  bbox = platform;
}//here every local object gets destroyed including platformShape (not OK, you still have a pointer to it) and platformFixture (ok to destroy)

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.

edit:

Another problem is right here:

  b2PolygonShape platformShape;  //creates a b2PolygonShape
  platformShape.SetAsBox(hx, hy);//modifies it
  b2FixtureDef platformFixture;  //creates a definition object
  platformFixture.shape = &platformShape;// saves a pointer to a local object (potentially dangerous, try not to do this)
  platform->CreateFixture(&platformFixture);// copies the information from the local b2FixtureDef
  bbox = platform;
}//here every local object gets destroyed including platformShape (not OK, you still have a pointer to it) and platformFixture (ok to destroy)
Source Link
PeterT
  • 626
  • 6
  • 8

Your main problem is that you keep copying and destroying values that you don't mean to destroy.

Let's take for example world

When you call platform.setAsPlatform(2.0f, 50.0f, world); you make a copy of world because setAsPlatform takes a b2World by value.

You probably meant to write

void entity::setAsPlayer(float hx, float hy, b2World &world)

This would take world per reference and not make a copy which is destroyed at the end of the function. So you added your objects to a copy of your world that you then destroyed, so when the object then tries to look up anything in the world that it's in it'll access already freed up memory as the 0xfeeefeee indicates.