QuiltMC / quilt-standard-libraries

A set of libraries to assist in making Quilt mods.
Apache License 2.0
152 stars 85 forks source link

Add missing null handling to `GroupResourcePack` #342

Closed soir20 closed 1 month ago

soir20 commented 1 year ago

Currently, two methods in GroupResourcePack will throw NullPointerExceptions if there is no pack for the given namespace. I've tweaked these methods so that the GroupResourcePack won't crash the game in these circumstances.

This isn't an issue when no other mods are present because vanilla also scans packs by namespace. However, I develop a mod that originally listed resources in all packs, regardless of whether they contained a particular namespace, which caused the game to crash.

There's an existing null check in open(); this PR makes null handling consistent throughout the whole GroupResourcePack.

LambdAurora commented 1 year ago

I'm curious to see how you're listing those resources, in theory NPE should never be thrown if resources are interacted with correctly.

soir20 commented 1 year ago

My mod adds a resource pack that scans other packs for certain resources. I streamResourcePacks() from the ResourceManager and query resources from them directly to prevent infinite recursion and to query root resources.

Specifically, I was calling listResources() directly on the resource packs, rather than going through the ResourceManager. This has since been fixed to check that the pack has the given namespace, so there's no longer a crash. However, I don't think Quilt should crash in these circumstances because vanilla packs do not; there should at least be a descriptive exception if this is intended.

OroArmor commented 1 month ago

"Merged" with 50309c1