Skip to content

Crash "Pose stack not empty" caused by unguarded PoseStack push/pop in RenderCustomModel.renderItem() #20

Description

@Krastik

Description

Game crashes with java.lang.IllegalStateException: Pose stack not empty
during world rendering when an NPC using a Geckolib model holds an item.

Root cause

In RenderCustomModel.renderItem(), poseStack.pushPose() and
poseStack.popPose() are not exception-safe:

poseStack.pushPose();
... transforms ...
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ...);
poseStack.popPose();

If renderStatic(...) throws for any reason (broken/unsupported item
render, etc.), popPose() is skipped, leaving the frame's PoseStack
unbalanced. Minecraft's own end-of-frame check in LevelRenderer then
throws "Pose stack not empty" and crashes the whole game — not just
the NPC render.

Suggested fix

Wrap the push/pop in try/finally so the stack is always balanced,
even if item rendering fails:

poseStack.pushPose();
try {
    ... transforms ...
    Minecraft.getInstance().getItemRenderer().renderStatic(stack, ...);
} catch (Throwable t) {
    // don't let one broken item crash the whole render frame
} finally {
    poseStack.popPose();
}

This has zero effect on the normal render path — it only prevents a
single failed item render from taking down the entire game.

Crash report

(прикрепи файл crash-2026-07-26_09.50.09-client.txt или вставь ключевую часть —
особенно стектрейс "IllegalStateException: Pose stack not empty" и Mod List)

Environment

  • Minecraft 1.20.1, Forge 47.4.10

crashReport.txt

  • CNPC-Gecko-Addon 1.20.1-1.0.6
  • CustomNPCs GBPort Unofficial 1.20.1.20260227

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions