Descent3 icon indicating copy to clipboard operation
Descent3 copied to clipboard

Move away from C style arrays

Open bryanperris opened this issue 2 months ago • 6 comments

There are many classic C arrays allocated with fixes sizes, and some conditions that simply lack sane bounds checking, this leads to many potential invalid memory access exceptions, and is the culprit load file crash for Linux.

Instead of C arrays, use C++ std::array or std::vector classes instead.

bryanperris avatar Apr 20 '24 16:04 bryanperris

I think this is a good idea in theory, but I think it will take a massive amount of work. There are a lot of pointers to arrays used. Something I think we can look at in the future, but I think we have bigger fish to fry for a while.

kevinbentley avatar Apr 20 '24 16:04 kevinbentley

Isn't this part of moving towards modern C++?

bryanperris avatar Apr 20 '24 17:04 bryanperris

We can enforce using modern C++ for newly added code, but re-writing existing code for the sake of it is likely to introduce more problems that it would solve

Lgt2x avatar Apr 20 '24 17:04 Lgt2x

I thought the whole codebase was basically going to be re-written into modern C++, not just mixing it. I know for now, lots of legacy stuff just needs to be fixed to get things at stable point. It is why I thought of unit testing should be started early on, so later when classic code is moved over to modern C++, the tests can ensure things still correctly work.

bryanperris avatar Apr 20 '24 17:04 bryanperris

Descent3 is around 1 million lines of C++, it'll be a while before we rewrite all of that =)

I do agree that unit tests are a priority, and we're trying to figure out the best way to do them.

Lgt2x avatar Apr 20 '24 17:04 Lgt2x

I understand there is a lot of code, but how much of that is in the core system? What about moving the core engine into a separate library, like making it a cmake submodule.

Since we are using cmake here, you can leverage Gtest with cmake: https://google.github.io/googletest/quickstart-cmake.html

bryanperris avatar Apr 20 '24 17:04 bryanperris