Jump to content

[Patch] Fix issue with Waterlogged Tree Canopy Shadows disappearing


chaosmonkey
  • Fixed

This is a patch for a long standing issue; I know this isn't technically part of the beta, but it seems appropriate for this particular ocean fix to make it into this release.

There's an issue with the canopy shadows of overlapping canopies disappearing that can be seen by first loading into an area with overlapping trees, leaving the area, then returning to the area. To the player, it looks like there's a bunch of area not covered by canopy shadows.

image.png.a40ee0f0052ad93144859d6fb7e47243.png

Here's the fix that corrects the broken shadows.

diff --git a/scripts/components/canopyshadows.lua b/scripts/components/canopyshadows.lua
index c79d5e6..655a26b 100644
--- a/scripts/components/canopyshadows.lua
+++ b/scripts/components/canopyshadows.lua
@@ -37,8 +37,8 @@ function CanopyShadows:GenerateCanopyShadowPositions()

                 local shadetile_key = newx.."-"..newz
                 local shadetile = Canopyshadows[shadetile_key]
+                table.insert(self.canopy_positions, {newx, newz})
                 if not shadetile then
-                    table.insert(self.canopy_positions, {newx, newz})
                     Canopyshadows[shadetile_key] = {refs = 1, spawnrefs = 0}
                 else
                     shadetile.refs = shadetile.refs + 1
@@ -103,4 +103,4 @@ function CanopyShadows:DespawnShadows(ignore_entity_sleep)
     self.spawned = false
 end

Allow me to explain.

First, some context. There is a global object Canopyshadows which stores reference counting objects for the shadow effect. This is necessary because although the tiles of the canopy shadows must be tracked per tree, the actual shadow effect is world state and ends up shared by adjacent trees.

Here's the bug. Only the tree that initialized one of those reference counting objects was actually recording that it had a shadow on that tile. Other trees would still increment the reference count, though. But because those other trees weren't tracking that they had a shadow in that position, they didn't decrement the reference count when they unloaded, and that ends up leaking the object in Canopyshadows. When the tree is reloaded, the object is still there and now it doesn't record that it has a shadow there, _and_ it can't turn on the shadow effect.

The fix is to always record the canopy location regardless of whether this tree initialized the reference counting object.


Steps to Reproduce

Spawn a few oceantree_pillar 4 tiles away from each other. Walk far enough to way and unload them all, then return. Observe that some of the shadows in the overlapping areas are missing.

After applying the patch, repeating this procedure should result in all of the shadows visible.

  • Like 1



User Feedback


A developer has marked this issue as fixed. This means that the issue has been addressed in the current development build and will likely be in the next update.
5 minutes ago, DiogoW said:

Appreciate the detailed report.

Certainly! My goal is making it quick/painless to land fixes like this to increase the likelihood that they are accepted.

Appreciate you fixing all these bugs.

Share this comment


Link to comment
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...