mikke89 / RmlUi

RmlUi - The HTML/CSS User Interface library evolved
https://mikke89.github.io/RmlUiDoc/
MIT License
2.77k stars 304 forks source link

Fix read access violation in the `bitmapfont` demo #583

Closed skaarj1989 closed 8 months ago

skaarj1989 commented 8 months ago

The font_interface should be cleared before Rml::Shutdown A valid render_interface (non nullptr) is required for unloading TextureResource in the font_interface

https://github.com/mikke89/RmlUi/blob/c54ef6ebc1f3eedf8c70a18fb8266ba97b96d4c7/Samples/basic/bitmapfont/src/FontEngineBitmap.cpp#L43

mikke89 commented 8 months ago

Thank you! I've been keeping a note on this bug for too long now.

However, I'm not sure if this is a sufficient fix. Since we keep a reference to the font interface inside RmlUi until shutdown, we easily risk use-after free here. Plus, it breaks the shutdown in reverse initialization order, which is a good idiom to follow.

If you look at the Rml::Shutdown procedure, you can see the appropriate shutdown order for the default interface. Ideally we would have the same order for the bitmap font engine. Any ideas?

mikke89 commented 8 months ago

I resolved this issue a bit differently: 64b36dc4775e3c2eefcd93bdb873cc402c0bbcea.

Thanks for reporting and the suggested solution.