SchmarrnDevs / Lighty

The Light Overlay Mod with a twist!
https://modrinth.com/mod/lighty
Apache License 2.0
18 stars 13 forks source link

MC 1.21 + Fabric: Lighty scares me by showing 0/0 in whole chunks while debug screen says block light is 10. #78

Closed mk-pmb closed 1 month ago

mk-pmb commented 2 months ago

A few days ago I had a surprise creeper in a closed room that should have been well lit. So I enable lighty and see 0/0 on the floor 2m below a wall torch. As soon as I flipped a nearby trapdoor, the light levels on the floor were green again. Seems like all that was required was any kind of update to the chunk. For days, I assumed it was Minecraft being buggy. Now I discovered that in another corner of the same chunk (stairs to my pig pen) the debug screen says block light is 10, while lighty shows 0. So maybe it is a bug in lighty instead, making the creeper an unexplained mystery again.

Screenshot

How do I even start to debug this? My hunch is that it is about deferred chunk rendering, that Lighty would need to wait a fraction of a second longer before querying the light values. If trapdoor-flipping causes lighty to query again, that would explain why that suddenly makes the numbers green and nonzero.

andi-makes commented 2 months ago

Thank you for reporting this issue!

Your hunch is kind-of correct. Sometimes there is a race condition with Lighty computing the Overlay even though the LightMap isn't generated for that chunk yet. Personally, I've only encountered this when loading newly generated chunks, but I guess the race condition makes itself known in different ways on different machines.

I don't necessarily know how to exactly fix it, as I haven't found a good way to query if LightMap information is available or not.

You are also right, that Lighty only recomputes the Overlay when there's a block update, but also (of course) on initial load of the overlay, and that's where the race condition can happen.

As a workaround without placing/changing blocks: You can try switching to a different LightyMode (for example CarpetMode), and then switch back to the original LightyMode you were on (for example, NumberMode). That should fix the overlay for the chunk, if it doesn't, please let me know, because then this is a very different bug and I'd need to look into it in more detail.

mk-pmb commented 2 months ago

I can somewhat reliably reproduce it by pressing a button on a command block that will then teleport me from one of my bases to another. It may be related to having hundreds of farm animals in an almost-adjacent chunk north of the affected chunks.

Can you add a user-defined additional delay? Usually when I teleport, I don't need the overlay immediately, so I could try and set half a second of additional waiting. People could adjust the value to their machine's chunk loading times.

Edit: Not sure about the computational cost, but in theory you could auto-schedule a retry if the chunk has all zeroes but the blocks just behind the chunk's border are lit at 2 or brighter.

andi-makes commented 2 months ago

Thank you for the additional information! I'll look into it, adding a delay sounds like the easiest code-workaround right now, but maybe I'll find a proper fix. Thanks!

andi-makes commented 1 month ago

This got fixed in Lighty v3.0.0-beta.5 for Minecraft 1.21.3. Thank you for your patience!