Tomb-Editor
Tomb-Editor copied to clipboard
TE: Dangerous handling of vertex/index buffers for imported geometries
Imported geometry class in TE was seemingly put together in a big hurry without understanding of DirectX buffers concept. Namely, ImportedGeometryMesh
class is directly inherited from Mesh
class which contains all the rendering data (e.g. vertex/index buffers and layouts). Difference from wad objects (statics/moveables) is that ImportedGeometry
class directly contains all renderable meshes, without taking in consideration that same imported geometry object may be reused in different swapchains or even devices. Additionally, Device
itself is declared as static!
The most obvious indication of this problem is trying to depth-sort index buffer of a given imported geometry, which results in update collisions if mesh is rendered in 2 different viewports:
https://user-images.githubusercontent.com/3331699/129170199-c8f815bd-8f61-4b41-abfe-3376595fe686.mp4
Additionally, this scenario is gravely dangerous because it can result in occasional SEHException on DX side - probably because of a race condition when a buffer which is uploading for device on a first viewport is updating on a second viewport.
To fix this, ImportedGeometryMesh
should NOT be directly contained inside ImportedGeometry
class but use same system as WadRenderer
class does for moveables or statics.