Fix undefined totalWeight value crash