OpenTrespasser / JurassicParkTrespasser

A git-based fork of the Jurassic Park: Trespasser source code.
101 stars 25 forks source link

TexturePackSurface: avoid use after delete #95

Closed meekee7 closed 4 years ago

meekee7 commented 4 years ago

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. As a quick workaround, the pointers of the deleted nodes are cached. The cache is checked to avoid dereferencing those dangling pointers. A better solution, using either std::weak_ptr or automatic unlinking of nodes upon destruction, requires more research.