Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.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
程序结束时,进程返回0xC0000005 在C++上快速原型上工作时,我偶然发现了这个错误。现在,我读到了代码的意思是“访问违规”,但我完全不知道发生这种情况的原因。在缩小原因之后,我注意到它与我调用一个特定函数有关。然而,有趣的是,调用函数后代码不会立即崩溃,而是在执行结束后。换句话说,程序启动并正确执行(即使出现错误的函数似乎也能按预期工作),然后,在主程序完成后,程序会因错误代码而崩溃_C++ - Fatal编程技术网

程序结束时,进程返回0xC0000005 在C++上快速原型上工作时,我偶然发现了这个错误。现在,我读到了代码的意思是“访问违规”,但我完全不知道发生这种情况的原因。在缩小原因之后,我注意到它与我调用一个特定函数有关。然而,有趣的是,调用函数后代码不会立即崩溃,而是在执行结束后。换句话说,程序启动并正确执行(即使出现错误的函数似乎也能按预期工作),然后,在主程序完成后,程序会因错误代码而崩溃

程序结束时,进程返回0xC0000005 在C++上快速原型上工作时,我偶然发现了这个错误。现在,我读到了代码的意思是“访问违规”,但我完全不知道发生这种情况的原因。在缩小原因之后,我注意到它与我调用一个特定函数有关。然而,有趣的是,调用函数后代码不会立即崩溃,而是在执行结束后。换句话说,程序启动并正确执行(即使出现错误的函数似乎也能按预期工作),然后,在主程序完成后,程序会因错误代码而崩溃,c++,C++,在试图调试代码时,我逐行检查了有问题的函数,对每条指令进行注释,以查看其中所做的任何操作是否会导致程序崩溃。令人惊讶的是,无论我注释哪条指令,代码都会崩溃。实际上,我来注释掉函数中的每一条指令,留下一个存根,在调用时它什么也不做,程序在完成时仍然失败。但是,如果我注释掉调用本身,程序将停止发出错误代码。因此,解决这个问题的唯一合理方法就是根本不调用它,因为即使调用它并让它什么都不做也不起作用 我对这件事一无所知。我不知道发生了什么,也不知道为什么我的代码会这样 仅供参考,我将包括一些可能特别重要

在试图调试代码时,我逐行检查了有问题的函数,对每条指令进行注释,以查看其中所做的任何操作是否会导致程序崩溃。令人惊讶的是,无论我注释哪条指令,代码都会崩溃。实际上,我来注释掉函数中的每一条指令,留下一个存根,在调用时它什么也不做,程序在完成时仍然失败。但是,如果我注释掉调用本身,程序将停止发出错误代码。因此,解决这个问题的唯一合理方法就是根本不调用它,因为即使调用它并让它什么都不做也不起作用

我对这件事一无所知。我不知道发生了什么,也不知道为什么我的代码会这样

仅供参考,我将包括一些可能特别重要,也可能不特别重要的片段

a。下面是有问题的函数。请注意,在当前状态下,它什么也不做,但调用时代码仍然崩溃。请务必考虑到这是一个免费的功能

void createCollectable(entityx::EntityX& manager, TextureAtlas& atlas, unsigned int type)
{
    /*
    entityx::Entity collectable = manager.entities.create();

    collectable.assign<CollectableComponent>(type);
    collectable.assign<Scriptable>(std::bind(&collectableCallback, collectable));
    collectable.assign<Positionable>(sf::Vector2f(250.0f, 250.0f), sf::Vector2f(1.0f, 1.0f), sf::Vector2f(1.0f, 0.0f));
    collectable.assign<Movable>(0.0f, sf::Vector2f(0.0f, -220.0f));

    switch(type)
    {
    case CollectableIDs::EXTRA_BOMB:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 10.0f, 10.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("EXTRA_BOMB"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::EXTRA_LIFE:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 10.0f, 10.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("EXTRA_LIFE"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::POWER_LARGE:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 10.0f, 10.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POWER_LARGE"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::SUPER_POWER:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 10.0f, 10.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("SUPER_POWER"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::POWER_MEDIUM:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 7.5f, 7.5f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POWER_MEDIUM"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::POWER_SMALL:
        collectable.assign<Collidable>(createBoxCollisionShape(Game::collisionWorld, 5.0f, 5.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POWER_SMALL"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::MIASMA_LARGE:
        collectable.assign<Collidable>(createCircleCollisionShape(Game::collisionWorld, 5.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POINT_LARGE"), 201, sf::BlendAlpha);
        break;

    case CollectableIDs::MIASMA_SMALL:
        collectable.assign<Collidable>(createCircleCollisionShape(Game::collisionWorld, 5.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POINT_SMALL"), 201, sf::BlendAlpha);
        break;

    default:
        collectable.assign<Collidable>(createCircleCollisionShape(Game::collisionWorld, 5.0f, collectable));
        collectable.assign<Drawable>(atlas.getFrameAsSprite("POINT_SMALL"), 201, sf::BlendAlpha);
    }

    return collectable;
    */
 }
c。为了完整起见,下面是我在.hpp文件中声明free函数的方式

void createCollectable(entityx::EntityX& manager, TextureAtlas& atlas, unsigned int type);
d。以下自由函数的声明与前一个几乎相同,它的工作方式与预期相同,并且在调用时不会使进程异常返回。再说一次,这个是供参考的。请注意,使函数返回值与否与调用函数是否抛出无关(正如您从注释掉的第一个函数的返回中看到的,这表明它最初返回了一些东西,就像这个函数一样):

entityx::Entity createPlayer(entityx::entityx&manager、thor::ActionMap&ActionMap、TextureAtlas&playerAtlas) { entityx::Entity player=manager.entities.create(); player.assign(playerAtlas.getFrameAsSprite(“IDLE_1”,true),101,sf::BlendAlpha); player.assign(sf::Vector2f(100.0f,100.0f),sf::Vector2f(1.0f,1.0f),sf::Vector2f(1.0f,0.0f)); player.assign(0.0f,sf::Vector2f(0.0f,0.0f)); player.assign(); thor::ActionMap::CallbackSystem&CallbackSystem=(player.component())->CallbackSystem; callbackSystem.connect(actionID::LEFT_按钮_保持,std::bind(&moveLeftCallback,player)); callbackSystem.connect(actionId::RIGHT_BUTTON_hold,std::bind(&moveRightCallback,player)); callbackSystem.connect(actionID::UP_按钮_保持,std::bind(&moveUpCallback,player)); callbackSystem.connect(actionID::DOWN_按钮_保持,std::bind(&moveDownCallback,player)); callbackSystem.connect(actionId::HORIZONTAL_button_UNPRESSED,std::bind(&stopHorizontalMovementCallback,player)); callbackSystem.connect(actionId::垂直按钮\未按下,std::绑定(&stopVerticalMovementCallback,player)); callbackSystem.connect(actionID::FOCUS_按钮_按下,std::bind(&focusPlayerCallback,player)); callbackSystem.connect(actionId::FOCUS_BUTTON_UNPRESSED,std::bind(&unfocusPlayerCallback,player)); thor::FrameAnimation playerIdleAnimation; playerIdleAnimation.addFrame(0.25f,playerAtlas.getFrameAsRect(“空闲1”)); playerIdleAnimation.addFrame(0.25f,playerAtlas.getFrameAsRect(“空闲2”)); playeridelanimation.addFrame(0.25f,playerAtlas.getFrameAsRect(“IDLE_3”); playeridelanimation.addFrame(0.25f,playerAtlas.getFrameAsRect(“IDLE_4”); thor::FrameAnimation playerMoveLeftAnimation; playerMoveLeftAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“左1”)); playerMoveLeftAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“LEFT_2”); playerMoveLeftAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“LEFT_3”); playerMoveLeftAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“左四”)); thor::FrameAnimation PlayerOverlightAnimation; playerOverlightAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“右1”)); playerOverlightAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“右二”)); playerOverlightAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“RIGHT_3”); playerOverlightAnimation.addFrame(0.25f,playerTras.getFrameAsRect(“右四”)); 托尔:动画师、玩家、动画制作人; addAnimation(animationId::PLAYER_IDLE,playerIdleAnimation,sf::seconds(0.3f)); 添加动画(动画ID::播放器左移,播放器左移动画,sf::秒(0.3f)); addAnimation(animationId::PLAYER\u MOVE\u RIGHT,playerOverlightanimation,sf::seconds(0.3f)); playerAnimator.playAnimation(animationId::PLAYER\u IDLE,true); 播放机分配(播放机映像机); player.assign(createCircleCollisionShape(游戏::碰撞世界,2.5f,玩家)和onPlayerCollisionCallback); player.assign(createCircleCollisionShape(游戏::碰撞世界,25.0f,玩家)和onPlayerGrazeCallback); 玩家分配 ( 3. 3. 5.0f, 3.0f, 150.0华氏度, 0, 0, 0.0f, 假的 ); 返回球员; }
在此问题上的任何帮助都将不胜感激。我不认为给出一个使用过的库的列表会引起任何兴趣,因为这个问题似乎与它们中的任何一个都无关,但为了完整起见,这里的主要库是SFML、entityx和Box2D。

似乎
collisionWorldvoid createCollectable(entityx::EntityX& manager, TextureAtlas& atlas, unsigned int type);
entityx::Entity createPlayer(entityx::EntityX& manager, thor::ActionMap<unsigned int>& actionMap, TextureAtlas& playerAtlas)
{
    entityx::Entity player = manager.entities.create();

    player.assign<Drawable>(playerAtlas.getFrameAsSprite("IDLE_1", true), 101, sf::BlendAlpha);
    player.assign<Positionable>(sf::Vector2f(100.0f, 100.0f), sf::Vector2f(1.0f, 1.0f), sf::Vector2f(1.0f, 0.0f));
    player.assign<Movable>(0.0f, sf::Vector2f(0.0f, 0.0f));
    player.assign<Controllable>();

    thor::ActionMap<unsigned int>::CallbackSystem& callbackSystem = (player.component<Controllable>())->callbackSystem;

    callbackSystem.connect(ActionIDs::LEFT_BUTTON_HELD, std::bind(&moveLeftCallback, player));
    callbackSystem.connect(ActionIDs::RIGHT_BUTTON_HELD, std::bind(&moveRightCallback, player));
    callbackSystem.connect(ActionIDs::UP_BUTTON_HELD, std::bind(&moveUpCallback, player));
    callbackSystem.connect(ActionIDs::DOWN_BUTTON_HELD, std::bind(&moveDownCallback, player));
    callbackSystem.connect(ActionIDs::HORIZONTAL_BUTTONS_UNPRESSED, std::bind(&stopHorizontalMovementCallback, player));
    callbackSystem.connect(ActionIDs::VERTICAL_BUTTONS_UNPRESSED, std::bind(&stopVerticalMovementCallback, player));
    callbackSystem.connect(ActionIDs::FOCUS_BUTTON_PRESSED, std::bind(&focusPlayerCallback, player));
    callbackSystem.connect(ActionIDs::FOCUS_BUTTON_UNPRESSED, std::bind(&unfocusPlayerCallback, player));

    thor::FrameAnimation playerIdleAnimation;
    playerIdleAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("IDLE_1"));
    playerIdleAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("IDLE_2"));
    playerIdleAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("IDLE_3"));
    playerIdleAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("IDLE_4"));

    thor::FrameAnimation playerMoveLeftAnimation;
    playerMoveLeftAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("LEFT_1"));
    playerMoveLeftAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("LEFT_2"));
    playerMoveLeftAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("LEFT_3"));
    playerMoveLeftAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("LEFT_4"));

    thor::FrameAnimation playerMoveRightAnimation;
    playerMoveRightAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("RIGHT_1"));
    playerMoveRightAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("RIGHT_2"));
    playerMoveRightAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("RIGHT_3"));
    playerMoveRightAnimation.addFrame(0.25f, playerAtlas.getFrameAsRect("RIGHT_4"));

    thor::Animator<DrawableAsset, unsigned int> playerAnimator;
    playerAnimator.addAnimation(AnimationIDs::PLAYER_IDLE, playerIdleAnimation, sf::seconds(0.3f));
    playerAnimator.addAnimation(AnimationIDs::PLAYER_MOVE_LEFT, playerMoveLeftAnimation, sf::seconds(0.3f));
    playerAnimator.addAnimation(AnimationIDs::PLAYER_MOVE_RIGHT, playerMoveRightAnimation, sf::seconds(0.3f));
    playerAnimator.playAnimation(AnimationIDs::PLAYER_IDLE, true);

    player.assign<Animatable>(playerAnimator);
    player.assign<Collidable>(createCircleCollisionShape(Game::collisionWorld, 2.5f, player), &onPlayerCollisionCallback);
    player.assign<Grazeable>(createCircleCollisionShape(Game::collisionWorld, 25.0f, player), &onPlayerGrazeCallback);
    player.assign<PlayerComponent>
    (
        3,
        3,
        5.0f,
        3.0f,
        150.0f,
        0,
        0,
        0.0f,
        false
    );

    return player;
}
ContactListener contactListener;
collisionWorld.SetContactListener(&contactListener);
collisionWorld.SetContactListener(0);