OGRECave / ogre

scene-oriented, flexible 3D engine (C++, Python, C#, Java)
https://ogrecave.github.io/ogre/
MIT License
3.91k stars 963 forks source link

fix crashes when reusing a Dx11 program pointer. #3184

Closed creadmefford closed 1 month ago

creadmefford commented 1 month ago

Fix crash due to accessing freed memory in Dx11 HLSL program class.

Min repro case:

  1. compile a D3D11HLSLProgram based shader via prepare().
  2. trigger an unload while state=LOADSTATE_PREPARED. (see Resource::unload () snip below)
  3. this calls unprepareImpl() which only frees the cached string data and NOT the other 8 or so std::vectors.
  4. call prepare() again. the program will crash due while iterating the std::vector data containing freed strings.

Resource::unload(void) calls either unprepareImpl() or unloadImpl () depending on the 'old' load state of a shader program. if (old==LOADSTATE_PREPARED) { unprepareImpl(); else unloadImpl();