Fixed crash caused by lambda being captured by reference and being destroyed when getting out of scope