Fix 3D viewer crash bug. (fixes lp:673603 and lp:804778)