I think we can all agree it wasn’t the Ambien, that Roseanne Barr has a long history of spewing conspiracy theories and ugly attacks.

But her spectacular self-immolation has ignited a cultural debate in this country over race, online venom, cultural standards and — inevitably — President Trump.

Even as Barr, in a late-night tweestorm, blamed her racist slur against Valerie Jarrett on the sleep medication, and attacked some of her fellow cast members, she admitted that she was fully at fault:

“guys I did something unforgiveable so do not defend me. It was 2 in the morning and I was ambien tweeting -- it was memorial day too -- i went 2 far & do not want it defended -- it was egregious Indefensible.”

Fine. She’s right. There is no defense. What planet do you have to be on to talk about a black person and “Planet of the Apes”?

There is also no question that ABC knew exactly what it was getting, which is why network president Ben Sherwood told the New York Times back in March that “you can’t control Roseanne Barr. Many who have tried have failed.”

So obviously the network wasn’t unaware that Barr had a long history of tweeting ugly, unproven insults and wild conspiracy theories. And presumably she wasn’t on Ambien all those times.

Roseanne retweeted at one point that “ABC is allowing the Trump haters to control their station” — even though it was the network that provided the platform for her pro-Trump reboot in the first place.

The network gambled that she could revive her hit show — which she did, specifically tailored to appeal to Trump Country — and she did. But even as she was riding high, Roseanne couldn’t stay off the Twitter. And that cost her, the hundreds of people who worked on the show and the network that invested in her.

With so many pundits on the left blaming the Roseanne debacle on Trump — who, of course, had nothing to do with it besides enjoying the show’s success — it was only a matter of time before the president joined the fray.

It’s noteworthy that Trump made no comment on Barr’s racist tweet. Instead, he tweeted that Disney CEO Bob Iger “Bob Iger of ABC called Valerie Jarrett to let her know that ‘ABC does not tolerate comments like those’ made by Roseanne Barr. Gee, he never called President Donald J. Trump to apologize for the HORRIBLE statements made and said about me on ABC. Maybe I just didn’t get the call?”

I’m sure unfair things have been said about Trump on ABC News and every other network. I’m just as sure that they didn’t fall into the category of likening him to an ape.

But HBO’s Bill Maher, five years ago, did jokingly compare Trump’s hair to an orangutan. And ABC’s lightning-quick dumping of “Roseanne” does raise questions about the media and cultural standards used when public personalities say offensive things.

No action was taken against Joy Behar, for instance, when the “View” co-host mocked Vice President Pence’s religion. She eventually apologized, first privately and then publicly.

MSNBC took no action against Joy Reid when a torrent of her homophobic tweets surfaced from a decade ago. She ludicrously claimed that her account had been hacked, but also apologized for her “dumb” and “hateful” postings.

And ESPN action took no action against former “Sports Center” co-host Jemele Hill for calling the president a “white supremacist” and “bigot.” But the network suspended her for suggestion a boycott of the Dallas Cowboys for cracking down on player protests.

On the other hand, CNN fired host Reza Aslan for tweeting that Trump was a “piece of s---” and “embarrassment to humankind.”

CNN also fired pro-Trump contributor Jeffrey Lord for tweeting the Nazi salute “Sieg Heil.”

Sarah Sanders weighed in Wednesday, saying:

“Where was Bob Iger‘s apology to the White House staff for Jemele Hill calling the president and anyone associated with him a white supremacist? To Christians around the world for Joy Behar calling Christianity a mental illness? Where was the apology for Kathy Griffin going on a profane rant against the president on ‘The View’ after a photo showed her holding President Trump’s decapitated head? And where was the apology from Bob Iger for ESPN hiring Keith Olbermann after his numerous expletive-laced tweets attacking the president as a Nazi and even expanding his role after that attack against the president’s family?”

Those are legitimate questions. In fairness, CNN dumped Griffin, and Olbermann, who made some extremely harsh anti-Trump videos for GQ, is being used by ESPN only on sports. But would the treatment have been different if the target wasn’t Trump?

The bottom line is that each media organization sets its own standards, depending on the gravity of the offense, the popularity of the performer and the person’s past record.

These problems were once far easier to sweep under the rug. But we all live in Twitter’s world now, where one ill-chosen phrase can end a career and online mobs can form at a moment’s notice.

Roseanne Barr woke up Tuesday morning with the most popular show on television. But hours later she was unemployed because she touched the third rail of racism, and ABC executives concluded she had crossed a very bright line.