Canvas Renderer

Canvas Renderer

202k Downloads

Building meshes with sprites inside of UnbakedModel.bake throws NPEs

2xsaiko opened this issue ยท 3 comments

commented

QuadEmitter.emit (grondag.canvas.apiimpl.mesh.MeshBuilderImpl$Maker.emit) fails when QuadEmitter.sprite is called beforehand since that calls setSpriteUnmapped which causes unmapSpritesIfNeeded (called from emit) to call unmapSprite which ends up calling MinecraftClient.getSpriteAtlas which throws an NPE because BakedModelManager.atlasManager is null at that point.

This happens when trying to bake a mesh inside of UnbakedModel.bake. The crash does not occur with Indigo Renderer.

I worked around this by using the internal Canvas API grondag.canvas.apiimpl.mesh.MutableQuadViewImpl.spriteFloat instead of sprite which does not call setSpriteUnmapped, but that is not really a good way to solve it since it relies on internal API.

Related code: UnbakedWireModel.kt:371-375
(spriteFix which is there right now includes the aforementioned workaround for this, replacing this with standard sprite causes the crash to occur)

Stacktrace: https://paste.2x.ax/~saiko/bf68895d80cf5a81bf6f2edf94104d84f9c762e1

This is 2xsaiko/hctm-base#2.

commented

Does the fix actually render correctly?

commented

I think I can fix this by retrieving the SpriteAtlasManager directly from ModelLoader instead of waiting for it to be returned to the BakedModelManager. Will fix.

commented

Does the fix actually render correctly?

Yes, it does.