Fix the bug: When surface is null, it will crash