fix potential crash in edge-case layout situations