A fascinating look at how a billion-iteration loop can hide in plain sight when its internal logic is equally flawed. It is a masterclass in the bizarre synergy of nested programming errors.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
The Most Obscure Bug in Terraria
Added:When generating a world, have you ever sat down and watched each pass go by?
If you have... have you noticed anything? Well, the most obvious thing is probably how insanely slow generating the underground desert is... which is by far and away the slowest pass.
Relative to the rest, it seems to take an agonizing amount of seconds while the rest take just frames to go by. However, one pass you wouldn't clock as being slow is probably "Generating jungle ruins", or generating the Jungle Temple. Normally, these world structures are incredibly quick to generate. And if you're generating a normal world, this is true - the Jungle Temple's generation pass is so fast you'd miss it if you blinked.
But this isn't the case in Don't Dig Up worlds. When the Jungle Temple is generated there, it hangs for a second before continuing as normal. And it's specifically this pass - the rest of them act normally. It's quite an interesting behavior. But what's probably more interesting is why it happens, which has absolutely nothing to do with Don't Dig Up.
This might be the most obscure fact on this entire channel.
This occurs because of a broken loop in Jungle Temple generation.
In normal worlds, the Jungle Temple will generate on any jungle grass tile, but in Don't Dig Up, since the temple spawns near the surface, it has different generation logic.
One part of this logic scans in a 10x10 tile radius to make sure it doesn't conflict with existing structure tiles. However, this scan has a variable error in it.
This first loop is meant to count from the tile ten tiles left of the candidate tile to the tile ten tiles right of the candidate tile. Thus, it should count starting from candidate minus ten, and ends when the counter reaches candidate plus ten.
However, the loop is improperly written such that the ending condition is when the counter reaches counter plus ten, not candidate plus ten.
Well, a number is always less than itself plus ten, so this ends up being an infinite loop!
This loop will only ever terminate when the counter plus ten actually does an integer overflow, turning into a negative number, which finally satisfies its loop exit condition. That takes 2.147 billion iterations... quite a lot. Luckily, the code inside this loop is also broken for a completely different reason so this loop actually just doesn't do anything... so it's not actually that slow to run 2.147 billion times. Computers are fast enough to count 2.147 billion times pretty fast, so all this manifests as is a slight hiccup in world generation - which is probably why it hasn't been caught in the years since 1.4.4 came out.
In all, this is a pretty short and interesting example of a simple coding bug, and it really illustrates how the most nefarious bugs aren't the big catastrophic ones, but instead the ones that occur silently and only cause unintended behavior when you aren't looking.
Hello! If you enjoyed this video, please consider subscribing, as only a quarter of you are. Similar videos are on the left and right.
Either way though, thank you for watching, and good day and good bye! See you next fortnight.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23

SuperBike Factory Has Gone... What's Next for the Motorcycle Industry?
thatbikersimon
11K views•2026-07-22