Only write stack if it isn't null to Fix #2