PiMaker / ltcgi

Optimized plug-and-play realtime area lighting using the linearly transformed cosine algorithm for Unity/VRChat.
https://ltcgi.dev
Other
442 stars 25 forks source link

Add quick fix for duplicate migration folder creation #25

Closed shiyouganai closed 6 months ago

shiyouganai commented 1 year ago

This is a hack fix for a small, arcane issue that I don't know the exact root cause of, but the symptom was that when I deleted my manually installed version of LTCGI tonight and migrated to the package install via github url, the scripts created a handful of empty, duplicate folders in my Assets directory.

Steps to recreate bug:

  1. Create empty Unity project
  2. Install LTCGI package from git url
  3. Add LTCGI Controller to scene
  4. Delete LTCGI package and its Assets/ folders but leave scene as-is, then reinstall package

The function MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless (lol) is running multiple times and at least one subsequent invocation of the function beyond the first doesn't have its AssetDatabase.IsValidFolder calls return true, despite the folders existing.

I don't know why. It may have something to do with the nature of the asset database: the result of the folder creation may not be available via the API until some later point, depending on when the API is used? (This is beyond my level of Unity expertise. I was led to that hypothesis after reading the "Asset Import Order" part of this doc.)

So I made sure those folders are only checked once per whatever interval Unity resets static variables. I also removed the manual database refresh because I think if you're just using the AssetDatabase API you don't need to manually refresh.

If you know an actual not hack fix or just want to close this as a won't-fix, it's no big deal, but I figured I'd open it anyway!

PiMaker commented 12 months ago

Mh, I think the better fix here would be to change that function to just use System.IO.File and System.IO.Directory classes instead of the AssetDatabase methods, but maybe your solution would work too? I'd worry it might miss some scenarios if it doesn't always check the actual folder though.

The empty duplicate folder thing even plagues UdonSharp, so this isn't a unique issue at least...

PiMaker commented 6 months ago

This should be fixed in #26.