c++ - Unhandled exception at 0x000FBA44 in Top Down Shooter -
i posted question dealing linker errors... whatever reason errors went away , replaced this. when try run program, window opens , appears run, visual studio 2013 presents me error:
unhandled exception @ 0x000fba44 in top down shooter.exe: 0xc0000005: access violation reading location 0xccccccd0.
and takes me xutility file 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 on _mynextiter line. know happening? using iterators go through lists had, commented them out yet still error , i'm not sure why
edit: ok, after going through stack of methods called, last piece of code called mine this:
chunkmanager::chunkmanager(b2world *w){ abstractchunk *chunk = generatechunk(0, 0); loadedchunks.push_back(*chunk); (int = 0; < 64; i++){ (int p = 0; p < 64; p++){ if (std::rand() > .7){ abstractblock block(i, p, 0, w); } } } }
now remember when wrote thought strange because loadedchunks std::list... have never used lists thought strange list accept pointer pointer object in <> of list takes object... think might source of problem don't know how fix it
second edit: here chunkmanager class can see lists 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 void chunkmanager::destroy(){ (int = 0; < loadedchunks.size; i++){ loadedchunks. } } chunkmanager::chunkmanager(b2world *w){ abstractchunk* chunk = generatechunk(0, 0); loadedchunks.push_back(chunk); (int = 0; < 64; i++){ (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); (int = -1; < 2; i++){ (int p = -1; p < 2; p++){ loadchunk(i, p); } } }
your code denotes confusion on fundamental concepts value , identity in c++. example in
abstractchunk *chunk = generatechunk(0, 0);
seems generatechunk
allocate object on free store. in:
loadedchunks.push_back(*chunk);
you storing a copy of allocated object in container , pointer never used later (thus leaking object).
wildly guessing name, abstractchunk
abstract class derived classes , list should heterogeneous list of chunks of different types.
this not possible in c++ (see fundamental concepts of "slicing" , "copy semantic" of c++). need use list of pointers chunks instead.
note piling long stream of statements without understanding how things works suicide strategy c++. fact assume if make mistake system tell denotes don't know how c++ works (see "undefined behavior" concept).
c++ cannot learned experimentation. need read a book or two cover cover first.
there no way learn c++ except reading (and smarter worse guessing approach work... reason in quite few places correct answer not logical, consequence of historic accident).
Comments
Post a Comment