add safe code in clear function that no img no clear callback