Skip to content

Commit

Permalink
Fixing incorrect usage of std::shared_ptr
Browse files Browse the repository at this point in the history
We were creating a new shared_ptr over the address of a Galaxy object which was
already owned by a few shared_ptrs. This meant meant that when the new
std::shared_ptr was destroyed the Galaxy underneath was also destroyed,
invalidating the other shared_ptrs, and bringing chaos to shark.

We were using this new shared_ptr only to avoid changing all the rest of the
code that used the -> syntax to access the members of the Galaxy object. The
correct way of doing this, avoiding deleting the underlying object, is of
course to use a raw Galaxy pointer.

Signed-off-by: Claudia Lagos <claudia.lagos@icrar.org>
  • Loading branch information
cdplagos committed Jul 20, 2018
1 parent 480ece8 commit 0636cb9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/gas_cooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ double GasCooling::cooling_rate(Subhalo &subhalo, Galaxy &galaxy, double z, doub
}

// Define main galaxy, which would accrete the cooled gas if any.
GalaxyPtr central_galaxy(&galaxy);
Galaxy *central_galaxy = &galaxy;

// If subhalo does not have a main galaxy (which could happen in satellite subhalos), or subhalo does not have a hot halo, return 0.
if(subhalo.hot_halo_gas.mass <= 0){
Expand Down

0 comments on commit 0636cb9

Please sign in to comment.