Realistic Terrain Generation

Realistic Terrain Generation

3M Downloads

ExceptionInInitializerError crash (RealisticBiomeHLBase.addBiomes())

whichonespink44 opened this issue ยท 11 comments

commented
commented

Ultimate cause is this line:
public static Block topBlock = hlBiome.topBlock;

Since it's static, it gets called when the class is initialized, which is an obnoxious early crash.

We need to make that a static routine. Actually in that class we can just take it out altogether, but similar code probably gets called in other classes.

I have no idea why it gets called earlier in Mohawky's setup than in ours. Same Highlands, RTG, and CC.

commented

And naggy Zeno comment: static is evil!

commented

I understand what static is, but... I don't understand why it's bad. Looks harmless enough, and like you pointed out, it's working fine for everyone else.

In any case, I'm all for following best practice, even if it means refactoring the entire codebase... would it be better to convert those kinds of static variables into member variables and initialise them during construction?

commented

The problems with static:
It gets created when the class is initialized. This may be very early and before things the routine needs exist (like here). This can create initialization tangles too when static var A initializing routine B which activates routine C which...
Static vars can't be cleared by the garbage collector, nor can anything they use get cleared, unless the class is unloaded (which tends not to happen)
If you end up needing more than one copy floating around (like for multiple dimensions, or for tests I admit I don't often do) you can't have it.

It's not something to justify rewriting existing code, but it's a good principle to ask "does it really HAVE to be static?". Especially with vars - static methods are less of an issue, at least as long as they're referentially transparent.

commented

I'll rewrite the Highlands biomes to not use static vars and we'll see if that fixes Mohawky's problem.

commented

"Static vars can't be cleared by the garbage collector, nor can anything they use get cleared, unless the class is unloaded (which tends not to happen)"

I've just been converted to the "Static is Evil" cult :)

Someone also pointed out in the forums that setting Highlands biomes to -1 in the configs causes a crash... could it be that Mohawky disabled the Bog biome by setting it to -1 and that's what's actually causing the crash?

commented

ding ding ding, I think
I was just looking at the routine and wondering "how the heck could it possibly be called prematurely"
I'll modify the code to check for that somehow.

commented

And ... a quick test shows that's the issue

commented

๐Ÿ‘

commented

PR in, with some other changes I can't easily exclude, but they shouldn't be issues.

commented

Fixed in 96e1938