It’s one those enduring mysteries of cinema: How does Terry Gilliam continue to attract such cascades of goodwill? I don’t know anyone who wouldn’t dearly love the maverick to finally produce the masterpiece he’s been threatening his whole career. For many years now each new film has been a flawed, compromised release, but we always accept Mr. Gilliam’s word that it wasn’t his fault this time ( the death of a principle actor , the Weinsteins) and eagerly come back for more, desperately hoping that this will be the one. You can imagine executives feeling the same, warming to his passion and unbridled energy and taking a chance on his perpetually roving and fearless imagination. Somehow, anyway, Mr. Gilliam managed to convince a new round of financiers to give him another shot, and from all accounts it was pretty much plain sailing this time.

Mr. Gilliam’s only complaint is that the budget was reportedly the lowest he’d ever worked with, but conversely it looks like his most expensive release since the 1990s. Obviously we have the wonderful (relative) cheapness of digital effects to thank for that, but there are still some pretty extravagant looking sets on display and in no way does this look like cut-price Gilliam. In fact, he’s at his most unencumbered and adventurous, both visually and in terms of ideas, but unsurprisingly the film is let down by more prosaic failures like characterization and a script that could have swapped some of its mannerisms for more meat.

Qohen (Christoph Waltz) is an alienated ant-worker for the faceless ManCom corporation who spends his days “entity crunching” — an ill-defined procedure that somehow involves deciphering digitally-rendered real-life conundrums. Like the rest of us, he’s desperate to work from home, primarily because he’s been waiting his whole life for someone to ring his antediluvian landline, as a result of a haunting and deeply embedded childhood memory. Sensing disenchantment, the management allows him his wish in return for his cooperation on new project: cracking a code that may unlock the secrets of life itself, but will probably also drive him mad while doing it. As Qohen — and seemingly everyone else in the film — is halfway there anyway, this doesn’t seem like too much of a deciding factor. Once he’s got his computer set up in his glorious abode, the management keeps distracting him with unhelpful assistants, such as company whiz kid Bob (Lucas Hedges) and the beautiful Bainsley (Mélanie Thierry), a teasing temptress who invites him into the euphoric virtual realm she frequents. As Qohen’s grip on reality begins to fracture, he starts to wonder if he might be more likely to find eternal happiness in Bainsley’s blissfully ignorant virtual paradise than in solving the world’s riddles.

Mr. Gilliam’s future world is very similar in concept to countless recent sci-fi films: Streets are filled with personalized video displays; youngsters are permanently plugged into networked accessories; and societal cornerstones like the workplace, medicine, sex and food have been commoditized and corporatiszd beyond even what we’re used to in 2013. But Mr. Gilliam does give his future world its own distinct look, a candy-colored, tacky, disposable cheapness that probably befits a real world that’s running out of more durable natural substances.

The costumes by Carlo Poggioli are similarly garish; wild Day-Glo garments that are strictly in line with — and equally ridiculous as — the haute-couture brand of futurism of “The Fifth Element,” but in keeping with the general tone.

Mr. Gilliam and production designer David Warren save costs by only shooting a few exterior scenes, allowing them to really go wild with the interiors where most of the action takes place. And there are some fabulous sets here, from an unsettlingly large, classically Gilliam medical examination room to the steampunk mechanics of ManCom’s central server room. But the best of them is Qohen’s majestic, burnt-out, graffitied former priory, frequented by fluttering doves that seem to have been flown in from Tony Scott’s “The Hunger.”

Whether it’s the doves or the tacky, nostalgic production design, the whole film has a very 1980s look to it; and combined with the oddball story and wacky humor, it more specifically resembles Polish science fiction of the ’80s. Perhaps it’s also something to do with Mr. Waltz’s bald dome, which brings to mind the ever present Marek Walczewski from such films.

Mr. Gilliam gets several chances to show off some his favorite moves: distorted wide-angle close-ups, disorientingly disproportioned rooms and an artificially idyllic fantasy island that’s as pure Gilliam as can be.

The performances are all over-the-top and demented, and it’s nice to see that all of the A-listers recruited into supporting roles are game enough to get in the spirit. Famously, there’s the scene of Tilda Swinton performing an awful rap, which is likely endure as a self-contained, excerpted YouTube favorite even if the film itself is unlikely to. Once a fat dwarf ambles into proceedings, we’re left with few boxes on our Gilliam checklist to tick off.

However, it’s the lesser stars in the leading roles that are the source of the film’s failings. Ms. Thierry is perfectly fine as Bainsley, but Mr. Hedges struggles in an admittedly weakly written role of Bob. The long scenes Bob shares with Qohen in the film’s midsection are draining and dull, with both actors noticeably struggling to strike up the rapport their onscreen relationship requires. It’s at that point of the film that my attentiveness began to wane — which is a shame because the finale was relatively strong and spirited, but by then not enough to rouse me back into engagement.

The major problem is Mr. Waltz. A natural-born supporting player if ever there was one, Mr. Waltz might be able to carry off a leading role if it wasn’t such a difficult, desperately uncharismatic character as this. Qohen is a distant, almost robotic character, but he’s essentially our only anchor in Mr. Gilliam’s unhinged universe so we need to be more attuned to his needs and desires than we’re allowed. It’s one of those cases where you can imagine producers considering that last resort of post-production tinkering: the voice-over. It must just have worked.

Debutant Pat Rushin’s script is chock-full of interesting ideas, but also too crammed with quirks that eventually become annoying. For example, not one but three characters have a signature verbal tic: Qohen refers to himself in the first-person plural; Bob uses the name “Bob” for everyone; and Qohen’s line manager (David Thewlis) repeatedly misnames him as “Quinn.” By the end of the film, we’re clamoring for them to be overcome, for our own blessed relief most of all.

Every review of “The Zero Theorem” is going to sign off with the observation that being finally free of constraints hasn’t done Mr. Gilliam any favors, and this time he’s got nobody else to blame but himself for his film’s shortcomings. I wouldn’t argue against such a sentiment, but Mr. Gilliam’s just such a loveable character, isn’t he? I find it impossible not to believe there’s another classic work in him, and I could probably conceive a number of contorted rationales to inspire hope for the future. Now that he’s out-Gilliamed himself, perhaps his imagination will be freed up to explore promising new potentialities? Until the next time, at least, Terry. Until the next time.