Former Shameless and EastEnders actor Jody Latham broke down in tears as he was spared a jail sentence for growing cannabis.
Latham, who recently dated X Factor judge Tulisa Contostavlos, began crying in the dock as a judge told him his "sophisticated" production of the drug could only warrant a prison term.
But the 29-year-old's tears of anguish turned to relief when he learned the 12-month sentence would be suspended for two years.
He pleaded guilty at an earlier hearing at Burnley Crown Court to the production of cannabis between March and May last year.
Police seized 24 plants behind the partitioned wall of a garage at former girlfriend Sarah Melia's home in the Lancashire village of Stacksteads.
Tests later showed 16 of the plants had matured and were capable of being sold for up to £9,000.
Habitual cannabis user Latham told the court he grew the plants because he was worried that buying from dealers would attract attention with his celebrity status.
Judge Beverley Lunt told him the simple solution was not to buy cannabis in the first place.
She warned him he would be brought before her again if he committed another offence and would be jailed.
"I hope this will you deter you from offending and make you give up this drug," she said.
Latham, who found fame when he played Philip "Lip" Gallagher in Channel 4's Shameless and later as pimp Rob Grayson in the BBC1 soap EastEnders, has a number of previous convictions, including two cautions for offences involving cannabis.
Prosecutor Sarah Statham described how police had found the small cannabis factory after being called to the address over an alleged assault.
Mother-of-three Melia, 31, of Bacup, admitted at an earlier hearing to permitting the drug to be produced, and was given a 12-month community order and told to perform 40 hours of work.