chrxh / alien

ALIEN is a CUDA-powered artificial life simulation program.
https://alien-project.org
BSD 3-Clause "New" or "Revised" License
4.85k stars 152 forks source link

SimulationCudaFacade tries to double-free CUDA alocations #101

Closed ChrisKitching closed 1 month ago

ChrisKitching commented 1 month ago

cudaDeviceReset() destroys all memory allocations on the device (among other things).

~SimulationCudaFacade() calls cudaDeviceReset() at the end of its destructor, meaning that the subsequent destruction of some of its members (such as EditKernelsLauncher) ends up trying to cudaFree these allocations after they were already freed by cudaDeviceReset. Fishy.

The program gets away with this by ignoring the return codes, but that's perhaps a bit dubious. A bit of refactoring of the object lifecycles might be called for (as well as not ignoring cuda return codes).

(I tripped over this while fiddling with something else using SCALE's exception mode, which found this unrelated problem :P ).

chrxh commented 1 month ago

Thanks for pointing out this error! I have just corrected it (and added a check).