Skip to content
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

Resolve dangling link pointers of STextureQuadNodes #97

Open
meekee7 opened this issue May 8, 2020 · 2 comments
Open

Resolve dangling link pointers of STextureQuadNodes #97

meekee7 opened this issue May 8, 2020 · 2 comments

Comments

@meekee7
Copy link
Contributor

meekee7 commented May 8, 2020

CPackedRaster manages trees of STextureQuadNode objects. Those nodes are "linked" to each other via pointers. When a node is deleted, those link pointers are left dangling. When such a dangling pointer is dereferenced, this raises complaints when additional memory access validation (full page heap verification) is enabled.
A quick workaround is proposed in PR #95: cache deleted pointers to avoid using them again. However, that workaround is rather "dirty" and, to an extend, also incomplete. (What if a pointer becomes valid again? When can we remove from or clear the cache?)

A clean solution should be seeked. Key options include:

  • use std::weak_ptr for the linkage pointers. However, the required switch to std::shared_ptr for all the STextureQuadNode pointers could have a significant performance penalty.
  • Reset link pointers when a node is about to be destroyed. This could require searching the entire tree, which is probably expensive.
  • Store the linking data another way
@meekee7
Copy link
Contributor Author

meekee7 commented Jun 10, 2020

A naive switch of the link pointers to std::weak_ptr, retrieved by making STextureQuadNode inherit from std::enable_shared_from_this and calling weak_from_this, does not work as expected. The effect is about the same as having the link pointer always be nullptr: the terrain texture in close proximity gradually loses resolution until it becomes extremely very low-res.
TPass024

@meekee7
Copy link
Contributor Author

meekee7 commented Nov 14, 2020

For reference, I have put the aforementioned std::weak_ptr attempt on a branch: https://github.com/meekee7/JurassicParkTrespasser/tree/texturepacksurface-weak-ptr
The relevant changes are in commit #aae263f.
meekee7@aae263f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant