Pehkui

Pehkui

35M Downloads

[Bug]: StackOverflowException - TypedScaleModifier

ByThePowerOfScience opened this issue ยท 4 comments

commented

Minecraft version(s)

1.20.1

Mod loader

Forge

Mod loader version

47.2.30

In what kind of world or server did the problem occur?

My multiplayer server that I was running

What went wrong? (Crash logs don't go here)

Hiya, mod dev here. Saw some stackoverflows in the logs: https://mclo.gs/yEODMf5

I checked with Mixin export enabled, and nothing's mixing into it. It just seems like a minor oversight in TypedScaleModifier:

return type == scaleData.getScaleType() ? modifiedScale : (float) operation.applyAsDouble(modifiedScale, type.getScaleData(scaleData.getEntity()).getScale(delta));

TypedScaleModifier#modifyScale calls ScaleData#getScale which then, whoops, calls ScaleModifier#modifyScale. ๐Ÿ˜ฌ

public float getScale(float delta)
{
final Entity e = getEntity();
final boolean canCache = delta == 1.0F && e != null && e.getEntityWorld() != null && !e.getEntityWorld().isClient && (e.getType() != EntityType.PLAYER || !getScaleType().getAffectsDimensions()) && !((PehkuiEntityExtensions) e).pehkui_isFirstUpdate();
if (canCache && !Float.isNaN(cachedScale))
{
return cachedScale;
}
float value = getBaseScale(delta);
for (final ScaleModifier m : getBaseValueModifiers())
{
value = m.modifyScale(this, value, delta);
}
if (canCache)
{
cachedScale = value;
}
return value;
}

value = m.modifyScale(this, value, delta);

Seems like this is causing an infinite loop of the same scale modifier getting hit every time, eventually resulting in a stack overflow.

Normally I'd offer a suggestion on how to fix it or make a PR myself, but I can't see an obvious solution without knowing more about the internals, so I'm making an issue instead.

Full list of installed mods and their version numbers

Biomancy 2.8.1.0, as well as a very large modpack that somehow doesn't have anything to do with this.

Did the problem cause the game to crash?

No, because it's on another thread, but it does stop the scaling from activating.

commented

Did that also occur on your server? Does the problem not happen e.g. in singleplayer?

commented

TypedScaleModifier prevents a stackoverflow by comparing the modifier's type against the type of the ScaleData argument, and returns the passed scale if they're the same. Seems Biomancy doesn't do that sort of check for their custom scale modifier, so this is likely an issue on their end. A simple fix would be for them to use TypedScaleModifier instead of their custom one.

commented

Welp, I'll file the report there then. Thanks for looking into it!

commented

@Virtuoel Wanted to let you know: mixin-patching it to use TypedScaleModifier resulted in the same issue occurring, just without their anonymous class appearing in the stacktrace.