Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 销毁Box2D正文-读取访问冲突错误_C++_Box2d - Fatal编程技术网

C++ 销毁Box2D正文-读取访问冲突错误

C++ 销毁Box2D正文-读取访问冲突错误,c++,box2d,C++,Box2d,我试图销毁一个Box2D实体,但每次我试图销毁它时,我的游戏都会崩溃,因为读访问冲突错误 删除正文的代码: if (event.mouseButton.button == sf::Mouse::Left) { if (((chunk.getChunkPosition().x + MAX_CHUNK_WIDTH * 16 > block.x * 16) && (block.x * 16 >= chunk.getChunkPosition().x))

我试图销毁一个Box2D实体,但每次我试图销毁它时,我的游戏都会崩溃,因为读访问冲突错误

删除正文的代码:

if (event.mouseButton.button == sf::Mouse::Left) {
    if (((chunk.getChunkPosition().x + MAX_CHUNK_WIDTH * 16 > block.x * 16)
      && (block.x * 16 >= chunk.getChunkPosition().x))
      && ((chunk.getChunkPosition().y + MAX_CHUNK_HEIGHT * 16 > block.y * 16)
      && (block.y * 16 >= chunk.getChunkPosition().y)))
    {
        chunk.blockPhysic[block.x][block.y]->setCreatedState(false);
        world.getBWorld()->DestroyBody(chunk.blockPhysic[block.x][block.y]->getBody());
    }
}
创建主体/块的代码:

BlockPhysic::BlockPhysic(b2World* world, const sf::Vector2f& _position, const int& _textureKeyID, const sf::IntRect& _textRect, sf::Vector2f _size, bool _dynamicBody)
{
    b2BodyDef bBodyDef;
    dynamicBody = _dynamicBody;
    bBodyDef.type = _dynamicBody == true ? b2_dynamicBody : b2_staticBody;
    bBodyDef.position.Set(_position.x, _position.y);
    rBody = world->CreateBody(&bBodyDef);

    b2PolygonShape bShape;
    bShape.SetAsBox(_size.x / 2, _size.y / 2);
    b2FixtureDef bFixtureDef;
    bFixtureDef.shape = &bShape;
    bFixtureDef.density = 0.0f;
    bFixtureDef.friction = 0.0f;
    rFixture = rBody->CreateFixture(&bFixtureDef);

    sf::Texture *texture = &Global::txtManager.textures.at(_textureKeyID);
    rSprite.setTexture(*texture);
    rSprite.setOrigin(_size.x / 2, _size.y / 2);
    rSprite.setTextureRect(sf::IntRect(_textRect.left, _textRect.top, _textRect.width, _textRect.height));
    rSprite.setPosition(_position.x, _position.y);
    created = true;
}

在你删除尸体的代码中,我没有看到任何关于尸体是否已经被销毁的检查。进行这样的检查可以防止内存问题;可能像你描述的那样