自上而下射击中0x000FBA44处的未处理异常 [英] Unhandled exception at 0x000FBA44 in Top Down Shooter

查看:422
本文介绍了自上而下射击中0x000FBA44处的未处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发布了一个处理链接器错误的问题......无论出于什么原因,这些错误消失了,并被替换为此。当我尝试运行我的程序时,窗口打开,它似乎运行,但Visual Studio 2013然后向我显示错误:

I recently posted a question dealing with linker errors... Well for whatever reason those errors went away and is replaced with this. When I try to run my program, the window opens and it appears to run, however Visual Studio 2013 then presents me with the error:

Unhandled exception at 0x000FBA44 in Top Down Shooter.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.

然后带我到带有断点的xutility文件:

And then takes me to a xutility file with a breakpoint here:

 #if _ITERATOR_DEBUG_LEVEL == 2
            if (_Myproxy != _Parent_proxy)
                {   // change parentage
                _Lockit _Lock(_LOCK_DEBUG);
                _Orphan_me();
                _Mynextiter = _Parent_proxy->_Myfirstiter;
                _Parent_proxy->_Myfirstiter = this;
                _Myproxy = _Parent_proxy;
                }

箭头位于_Mynextiter线上。有谁知道发生了什么?我最初使用迭代器帮助查看我的一些列表,但我对它们进行了评论但我仍然收到此错误,我不知道为什么

The arrow is on the _Mynextiter line. Does anyone know what is happening? I was initially using iterators to help go through some lists that I had, but I commented them out yet I still get this error and I'm not sure why

编辑:
好​​的,所以在回过头调用的方法之后,调用的最后一段代码是我的:

Ok, So after going back through the stack of methods called, the last piece of code that was called that was mine was this:

ChunkManager::ChunkManager(b2World *w){
    AbstractChunk *chunk = generateChunk(0, 0);

    loadedChunks.push_back(*chunk);

    for (int i = 0; i < 64; i++){
        for (int p = 0; p < 64; p++){

            if (std::rand() > .7){
                AbstractBlock block(i, p, 0, w);
            }

        }
    }
}

现在我记得当我写这篇文章时我觉得它很奇怪因为loadedChunks是一个std :: list ...我从来没有使用过列表所以我觉得奇怪的是列表只接受一个指向指针的指针对象在列表的<>中它显然需要一个对象...我想这可能是我的问题的根源但我不知道如何修复它

Now I remember when I wrote this I thought it was strange because loadedChunks is an std::list... I have never used lists so I thought it was strange that the list would only accept a pointer to a pointer to an object where in the <> of the list it clearly takes an object... I think this might be the source of my problem but I don't know how to fix it

第二次编辑:这是ChunkManager类,所以你可以看到我有的列表

Second Here is the ChunkManager class so you can see the lists I have

#pragma once

#include <iostream>
#include<list>
#include<vector>
#include "AbstractChunk.h"

#ifndef CHUNKMANAGER_H
#define CHUNKMANAGER_H

class ChunkManager
{
public:
    ChunkManager();
    ChunkManager(b2World *world);
    ~ChunkManager();
    bool isChunkLoaded(int x, int y);
    bool isChunkGenerated(int x, int y);
    void loadChunksArround(int x, int y);
    AbstractChunk* loadChunk(int x, int y);
    int unloadChunk(int x, int y);
    std::list<AbstractBlock>* getLoadedBlocks();
private:
    b2World *world;
    std::list<AbstractChunk> loadedChunks;
    std::list<AbstractBlock> loadedBlocks;
    AbstractChunk* generateChunk(int x, int y);
};

#endif

AbstractChunk.cpp:

AbstractChunk.cpp:

    #include "AbstractChunk.h"


    AbstractChunk::AbstractChunk()
    {
    }

    AbstractChunk::AbstractChunk(int x, int y){
        xpos = x;
        ypos = y;
    }

    int AbstractChunk::getXpos(){
        return xpos;
    }

    AbstractChunk::~AbstractChunk()
    {
    }

AbstractBlock.cpp:

#include "AbstractBlock.h"


AbstractBlock::AbstractBlock()
{
}

AbstractBlock::AbstractBlock(int x, int y, float roation, b2World *world){

}

sf::Sprite AbstractBlock::draw(){
    sf::Sprite sprite;
    return sprite;
}

void AbstractBlock::destroy(b2World *world){

}


AbstractBlock::~AbstractBlock()
{
}

ChunkManager.cpp:

ChunkManager.cpp:

#include "ChunkManager.h"


ChunkManager::ChunkManager(){

}

//Ignore this, working on it now
void ChunkManager::destroy(){
    for (int i = 0; i < loadedChunks.size; i++){
        loadedChunks.
    }
}

ChunkManager::ChunkManager(b2World *w){
    AbstractChunk* chunk = generateChunk(0, 0);

    loadedChunks.push_back(chunk);

    for (int i = 0; i < 64; i++){
        for (int p = 0; p < 64; p++){

            if (std::rand() > .7){
                AbstractBlock block(i, p, 0, w);
            }

        }
    }
}


std::list<AbstractBlock>* ChunkManager::getLoadedBlocks(){
    return &loadedBlocks;
}


ChunkManager::~ChunkManager()
{
}

AbstractChunk* ChunkManager::generateChunk(int x, int y){

    if (!isChunkGenerated(x,y)){
        AbstractChunk chunk(x, y);
        return &chunk;
    }
    else
        return nullptr;
}

bool ChunkManager::isChunkGenerated(int x, int y){
    return false;
}

AbstractChunk* ChunkManager::loadChunk(int x, int y){
    return nullptr;
}

void ChunkManager::loadChunksArround(int x, int y){

    int chunkX = std::floor(x / 16);
    int chunkY = std::floor(y / 16);

    for (int i = -1; i < 2; i++){
        for (int p = -1; p < 2; p++){
            loadChunk(i, p);
        }
    }

}


推荐答案

您的代码表示对C ++中的基本概念(如价值和身份)存在一些混淆。例如在

Your code denotes some confusion on very fundamental concepts like value and identity in C++. For example in

AbstractChunk *chunk = generateChunk(0, 0);

似乎 generateChunk 将分配一个对象免费商店。
然后在:

seems that generateChunk will allocate an object on the free store. Then however in:

loadedChunks.push_back(*chunk);

您在分配的对象中存储副本并且指针永远不会在以后使用(从而泄漏对象)。

you are storing a copy of the allocated object in a container and the pointer is never used later (thus leaking the object).

从名称中猜测, AbstractChunk 是一个摘要带有派生类的类,列表应该是不同类型的块的异构列表。

Wildly guessing from the name, AbstractChunk is an abstract class with derived classes and the list should be an heterogeneous list of chunks of different types.

这在C ++中是不可能的(参见切片的基本概念和C ++的复制语义)。您需要使用指向块的指针列表。

This is simply not possible in C++ (see the fundamental concepts of "slicing" and "copy semantic" of C++). You need to use a list of pointers to chunks instead.

请注意,在不深入理解工作原理的情况下堆积大量语句C ++的自杀策略。即使您假设如果您犯了错误,系统会告诉您,这表示您不知道C ++是如何工作的(参见未定义行为概念)。

Note that piling up a long stream of statements without understanding deeply how things works is a suicide strategy with C++. Even the fact that you assume that if you make a mistake the system will tell you so denotes you don't know how C++ works (see "undefined behavior" concept).

C ++无法通过实验学习。您需要先阅读一本好书或一本好书,然后再封面。

C++ cannot be learned by experimentation. You need to read a good book or two from cover to cover first.

除了通过阅读之外没有办法学习C ++(而且更聪明的是猜测方法会更糟糕......原因是在很多地方,正确的答案不符合逻辑,但结果是历史性事故)。

There is no way to learn C++ except than by reading (and the smarter you are the worse the guessing approach will work... the reason is that in quite a few places the correct answer is not logical, but a consequence of an historic accident).

这篇关于自上而下射击中0x000FBA44处的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆