DescentDevelopers / Descent3

Descent 3 by Outrage Entertainment
GNU General Public License v3.0
2.73k stars 231 forks source link

Fixed inconsistent use of memory management functions #445

Closed pzychotic closed 2 weeks ago

pzychotic commented 2 weeks ago

Pull Request Type

Description

Before #436 MEM_USE_RTL was a define in lib/mem.h that could be uncommented to change the memory management functions. So every library including mem.h was agreeing on the same memory functions.

By changing this to a CMake option and only enabling it on the Descent3 target, all other libraries would never activate this preprocessor definition when the option is enabled and therefore use different memory functions.

Allocating memory from any code of a library and freeing this memory from code compiled as part of Descent3, or vice versa, will result in memory corruption.

Related Issues

Fixes #444

Screenshots (if applicable)

Checklist

Additional Comments

winterheart commented 2 weeks ago

Probably is better to move target_compile_definitions into mem module, where it should belong to.

Lgt2x commented 2 weeks ago

Ugh I missed that at review. I agree that it should be a target_compile_definitions though

pzychotic commented 2 weeks ago

I understand why you would want to do that, but...

In order for this to work, every library that includes mem.h would also need a dependency to the mem target through target_link_libraries in order for that define to propagate correctly. Not a single library does that currently. This means changing close to 20 of our roughly 50 libraries.

And if than someone refactors parts of the project or includes mem.h in another lib that doesn't have the dependency yet, we might not even realize that we end up with the same runtime problems we got now.

Unless we can somehow detect this at build time, having this globally seems to be the save option.

Lgt2x commented 2 weeks ago

ok for this temporary fix, we can refactor later. I'll create an issue so we don't forget.

Lgt2x commented 2 weeks ago

See #447