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

fix crashes when reusing a Dx11 program pointer. #3184

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

creadmefford
Copy link
Contributor

@creadmefford creadmefford commented Aug 6, 2024

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();

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();

If you compile the source code via prepare() and it's state=LOADSTATE_PREPARED the old cleanup would only delete the allocated strings.  The other vector based buffers were never actually cleaned out so they hold pointers to invalid/freed memory.  If you re-prepare() the program the vector data is in a bad state and you get the crash.
@paroj paroj merged commit 7d76027 into OGRECave:master Aug 6, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

3 participants