Think about it.. If it is saying the line being called on 'id' is resulting in an invalid entity error, this means you should also put a check on the entity associated with 'id'.
PHP Code:
if ( !pev_valid( ent ) || !pev_valid( id ) )
return FMRES_IGNORED
__________________