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.
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;
}
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
Edit:
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);
}
}
}
}
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
Second Edit: 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:
#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:
#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);
}
}
}
See Question&Answers more detail:
os