-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use shared pointer inside Chunk Cache #173
Conversation
In very seldom cases Minnutor still crashes with memory access violations: If a Chunk gets removed from the Cache but still gets loaded or rendered, the data structure is removed from heap, but still written to. By using QSharedPointer<Chunk> always some routine has ownership and the heap is only freed when all routines are finished with processing.
@@ -44,7 +46,7 @@ void ChunkLoader::run() { | |||
return; | |||
} | |||
// get existing Chunk entry from Cache | |||
Chunk *chunk = cache.fetchCached(cx, cz); | |||
QSharedPointer<Chunk> chunk(cache.fetchCached(cx, cz)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using auto
more?
auto chunk = cache.fetchCached(cx, cz));
Doesn't matter then if it's a QSharedPointer
, std::shared_ptr
, naked pointer or whatever else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like auto that much, as you do not see the type of a variable in a normal editor.
(I know that this answer is contradictory to your (good) argument. Probably it is just personal style how much auto you use.)
With this kind of change, it is critical to check that the memory is actually freed eventually. It's easy for the shared pointers to keep things alive forever. |
I observe normal RAM usage. But you are right, we should test this very well. With the old code I still got (seldom) crashes. So there is need to change something. With the shared pointers I'm not able to reproduce these crashes at the moment. |
Just need to make sure we're not holding onto any qsharedpointers for no reason. |
There are 3 locations where these shared pointers are used:
So in my opinion we would notice quite fast if something is going wrong. |
In very seldom cases Minnutor still crashes with memory access
violations:
If a Chunk gets removed from the Cache but still gets loaded or
rendered, the data structure is removed from heap, but still written to.
By using QSharedPointer always some routine has ownership and the
heap is only freed when all routines are finished with processing.