Question

I seem to be having a very hard time trying to make a dynamic chunk management system in a multithreaded program. I have a class, VDimensia, which is a dimension filled with voxel chunks, and one thread of the multithreaded program is busy rendering and updating the voxels. My problem is that another thread is designed to destroy voxel chunks that are too far away, and it is causing problems when it deletes a chunk while the other thread is in the middle of creating and initializing the chunk. My code is a bit messy right now, what with all of the access checks I have in place, but I can't seem to find a way to keep the program from popping up with an access violation of some sort. Is there a way to use try catch to ignore the violation and continue? I have already tried to use __try __except, and it decides to lock the thread up, and I have tried to set the compiler option /EHa, and that does literally nothing. I am using Visual Studio 2012 C++. I am still learning C++ to this day, so any help is appreciated.

Was it helpful?

Solution

You might want to look into a ref counting solution, such as std::shared_ptr/std::weak_ptr and just let the thread that's updating voxels do its thing; when they're done and deref the voxel, the voxel can go away.

http://en.cppreference.com/w/cpp/memory/shared_ptr

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top