GalSim-developers / GalSim

The modular galaxy image simulation toolkit. Documentation:
http://galsim-developers.github.io/GalSim/
Other
224 stars 105 forks source link

Fix possible crash in PhotonArray.makeFromImage if image has negative pixels. #1216

Closed rmjarvis closed 1 year ago

rmjarvis commented 1 year ago

@g-braeunlich ran into a bug in the PhotonArray makeFromImage function where it would sometimes seg fault. It turned out that the calculation for how many photons would be needed was wrong when there were negative-flux pixels, so it wasn't allocating enough space and the arrays were being overrun. This PR fixes that bug.

It also happened to be the case that that function shouldn't even have been run for what Geri was doing. But he had the photon_ops set to [], rather than None. Those should logically mean the same thing, but GalSim assumed that since photon_ops wasn't None, it needed photons. Now photon_ops = () or [] means the same thing as None in the code.