I've been writing an engine and ran into a problem, I'm getting a read access violation in my code. I have no idea why, but it happens when I add this->chunks.push_back(chunk);
into this block of code,
void c_world::generate_world()
{
this->chunks.resize(MAX_CHUNKS);
for (auto chunk : this->chunks)
{
chunk.setup_landscape();
}
}
so it becomes...
void c_world::generate_world()
{
this->chunks.resize(MAX_CHUNKS);
for (auto chunk : this->chunks)
{
chunk.setup_landscape();
this->chunks.push_back(chunk);
}
}
this->chunks
is an std::vector<c_chunk>
(c_chunk) being a custom class. Thank you!
All helps appreciated.
EDIT: this was the right way to do it..
void c_world::generate_world()
{
for (std::uint32_t i = 0; i < MAX_CHUNKS; i++)
{
c_chunk chunk[MAX_CHUNKS];
chunk[i].setup_landscape();
this->chunks.push_back(chunk[i]);
}
}