They can get out depending on how the financing was structured and what sort of contracts were used.
You see it a lot with independent filmmakers when they're offered distribution. They're told that they'll get X% of the earnings for the film "after expenses" or something along those lines. In these types of contracts, the filmmaker almost never sees money because, suddenly, there are an awful lot of expenses in getting their film shown. Just so many.
Something similar can happen with film financing. Contracts can be made whereby if the film flops, underperforms, fails to make back X amount, etc. then the producer doesn't need to repay the money. It basically becomes a write-off and what money the film does make ends up in the producers' pockets.
The film The Producers is based around those kind of dodgy financial dealings; in their case, two stage producers oversell shares of a production they're sure will be terrible because of a loophole where if it flops, they keep the cash and walk off with everyone's money. That's a thing that can actually happen (unless they've closed that loophole lately.)