Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Crash on loading a chunk that contains heat exchangers #4067
BuildCraft version: 7.99.15
A pretty annoying bug. Nearly every time I load into my game this crash occurs. It doesn't occur 100% of the time so if I just keep trying to start my game eventually it will load and I can play.
Most often the crash occurs when I load my world. The crash happens on what seems to be the first tick. It can also occur when I travel a distance from my base and return. Once I get within a certain distance of my base after being away, the game crashes, and will continue to crash when I restart the game. Decreasing my render distance can temporarily alleviate this problem if the crash occurs when I'm returning to my base from far away. This lets me get closer to my base before the game crashes. Then I increase my render distance before I reload the world and that seems to help the game load (but not always).
While it occurs most frequently when I load my world, it can also occur in-game as well. In general, it seems to occur when certain chunks get unloaded and then reloaded. The chunks in question are around my base, which is where my bed is along with my workshop. The workshop contains a number of IC2 machines connected to a complicated item sorting system designed with buildcraft pipes. The sorting system itself is fed with a buildcraft quarry, which is powered by 6 iron engines fueled by a buildcraft oil refinery (which means several distillers, heat exchangers, and tanks all connected with buildcraft fluid pipes).
I'm reasonably confident the crash is being caused by buildcraft because I took a look at the crash logs from the numerous times the game crashed (the crash-reports folder has 50 reports in it, and they all appear to caused by the same thing). The crash seems to reference one of the heat exchangers in my oil refinery setup. The oil refinery is outdoors and away from my workshop, so there aren't blocks from other mods anywhere close to it. I built my base on the same hill where I spawned when I first started this world, so it's likely the refinery is within a spawn chunk.
I am a programmer and so naturally I investigated the problem myself. Please note I know nothing about the buildcraft or minecraft code bases, so take what I say with a grain of salt.
From my look at the crash logs, the bug always references a heat exchanger, but not always the same heat exchanger. Since the crash never occurs as long as I stay near to the base (and the oil refinery), I assume that the problem occurs on the first tick of when the chunk the oil refinery is in is loaded. The crash occurs on line 167, where it calls a method of an object it just retrieved by calling getFacing(). The getFacing() function returns null when the block's state object is null. I went further up the call chain as well. It's a series of other functions that ask another function for the block's state object, and then checks an assumption of the properties of the state and returns null if that assumption check fails.
My instincts tell me the bug is a race condition for the block's internal state object, which might not be set yet given it's the first tick the block was loaded, or is changed by somewhere else in the tick in such a manner as to cause one of those functions to return null.
In either case, what I would do is change findAdjacentExchangers() to return an empty Deque if thisFacing is null. If the assumptions the function is working under are faulty, it shouldn't act and instead wait for the next tick. I assume returning an empty array is a way to gracefully fail, as anything that calls that function will just assume that there are no adjacent heat exchangers for that tick. This, of course, assumes that whatever was causing thisFacing to be null corrects itself by the next tick, which should be the case for a race condition.
Of course, I don't know anything about the minecraft or buildcraft code bases besides my brief glimpse. If I'm totally wrong please don't mind my meaningless ramblings.
According to the crash report the block is air, rather than a heat exchanger, which is a bit odd. Fortunately it doesn't really matter, as your speculation seems to be about right, and checking to see if it is null is a trivial fix on our end, even if optifine has something todo with it.
Is it possible that #3616 is affecting you? (Specifically if using this resource pack fixes the FPS issues https://mod-buildcraft.com/releases/Misc/packs/buildcraft_fluid_still.zip)
Actually, loading that resource pack causes the game to crash again (same crash log as I posted earlier). I should mention that OptiFine is still disabled. However, my lag is caused by the tick. My tick is like 85% according to that pie chart. Given that I have a custom built gaming computer, I don't think rendering problems are an issue for me.
NVMD I found a tick profiler mod made by MinimallyCorrect. Oddly enough it says that I have 20 ticks per second. It claims that by far most of the time is spent on the client thread. In any case I tried enabling that disable animated fluids resource pack again by enabling it while my game was running, and my FPS went up significantly. However, it doesn't seem to have affected the fluids in any way. My fluid pipes still have moving liquid inside of them. Nevertheless the FPS, while not smooth, is now playable. Whatever that resource pack does, it helped a lot. So I guess I'm suffering from #3616.