Add nullptr checks in Window