for (b2ContactEdge* ce = playerBody->GetContactList(); ce; ce = ce->next) { b2Contact* c = ce->contact; for (int i = 0; i < coinBody.size(); i++) { if (c->GetFixtureA() == coinBody[i]->GetFixtureList()) { coinBody[i]->DestroyFixture(coinBody[i]->GetFixtureList()); coin.erase(coin.begin() + i); coinBody.erase(coinBody.begin() + i); } } } 

coin and coinBody are vectors:

 std::vector<Object> coin; std::vector<b2Body*> coinBody; 

(Object from SFML, b2Body from Box2D)

The meaning of the program. I create a platformer on an article on Habré, this part of the code should handle the player’s collision with a coin, during a collision the figure belonging to the coin body should be destroyed, and then the object and b2Body variables related to this coin can be removed from the corresponding vectors. The problem is that this line:

 coinBody[i]->DestroyFixture(coinBody[i]->GetFixtureList()); 

Causes an error when running the program:

read access violation 0xFDFDFDFD

The code is taken from the article on Habré "Create a platformer in 30 minutes", if you do not delete the shape, but immediately reduce the vector, the program does not crash, but the interaction is incorrect.

0