A man killed himself after watching a Ross Kemp documentary on Barlinnie prison because he was terrified of being sent there, a sheriff has ruled.
Robert Nobbs, 51, had been arrested and held on remand on charges of possessing indecent images of children and having a prohibited weapon.
He was being held at Low Moss prison in Bishopbriggs, near Glasgow, while awaiting his court appearance.
However, just hours after watching the ITV documentary Ross Kemp Behind Bars: Inside Barlinnie in November 2017, he was found dead in his cell.
Mr Nobbs left a note saying "he couldn't handle Barlinnie" and had previously spoken about being frightened of serving a sentence at the tough Glasgow jail.
A fatal accident inquiry was held at Glasgow Sheriff Court into Mr Nobbs' death.
The inquiry heard that former Eastenders star Kemp had implied sex offenders were the "lowest of the low" as he examined conditions for sex offenders at the prison during the show.
Sheriff Linda Ruxton has now ruled that watching the documentary was the "last straw" for Mr Nobbs, of Inverkip, Inverclyde.
She also criticised jail bosses at Low Moss for keeping him in isolated conditions at the prison which she said had an impact on his mental health.
Issuing her determination, Sheriff Ruxton said: "Shortly before his death, Mr Nobbs had been expressing to his sister his belief that he was going to receive a lengthy prison sentence and how afraid he was of going to Barlinnie. He was terrified at the prospect.
"On the evening before he died, in the course of a telephone call, Mr Nobbs had encouraged his parents to watch a television documentary due to be aired that night about Barlinnie.
"This was the Ross Kemp documentary about the Barlinnie prison depicting its reputation as one of the country’s most notorious jails.
"During the evening Mr Nobbs watched the documentary in his cell. At one point during it the subject of the incarceration of sex offenders was examined in the course of which Ross Kemp apparently made derogatory remarks, asking prison officers how they looked after such prisoners whom he implied were “the lowest of the low”.
"At this point Mr Nobbs would have been able to hear the reaction from the mainstream prison from others watching the programme. There was a noisy response with jeering and name calling."
She added: "I am satisfied that the evidence supports the conclusion that it is probable that the lack of an appropriate regime for offence-protected prisoners and consequently the highly restrictive conditions in which Mr Nobbs was held had a direct causal connection with Mr Nobbs’ death.
"It is equally likely that the documentary on Barlinnie acted as the trigger for his suicide. Mr Nobbs was terrified of being sent there and the documentary itself together with the response from the mainstream prisoners in Low Moss would have compounded those fears.
"He wrote in his letter that he could not handle Barlinnie. The programme, I suspect, was simply the last straw for Mr Nobbs."
Sheriff Ruxton said more support should have been offered to Mr Nobbs as he was a vulnerable inmate who had never been in prison before and was at high risk of suicide.
Last month, a former prisoner who appeared in the Ross Kemp documentary was found dead in an apparent murder suicide.
The bodies of Hugh Sinclair and partner Elizabeth McShane were discovered at a flat in Glasgow's Knightswood.
Sinclair, 33, was among the convicts who went in front of the cameras for the programme in 2017.