NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
459 stars 52 forks source link

bevy_asset_loader + trunk: Changes in assets folder trigger ~10 reloads #110

Closed cxreiff closed 1 year ago

cxreiff commented 1 year ago

I am using bevy_asset_loader and dynamic asset loading (a .manifest file) on an example repository created from @NiklasEi's template here (https://github.com/NiklasEi/bevy_game_template). When the app is served to a browser using Trunk, and anything is created or modified in the assets directory, it causes Trunk's automatic reloading functionality to trigger over and over again.

Trunk uses v4 of the notify crate, which is build on top of the FSEvents API on Mac OS, so I used fsevents to print out the filesystem events when adding an empty file to the assets directory with touch assets/test:

notify_events: Notifying events #: 1. /Users/jaxreiff/Documents/untitled/assets/test Created IsFile AttributeModified notify_events: Notifying events #: 4. /Users/jaxreiff/Documents/untitled/assets/textures/app_icon.png IsFile /Users/jaxreiff/Documents/untitled/assets/textures/kitty.png IsFile /Users/jaxreiff/Documents/untitled/assets/test Created IsFile AttributeModified /Users/jaxreiff/Documents/untitled/assets/manifest.assets IsFile notify_events: Notifying events #: 4. /Users/jaxreiff/Documents/untitled/assets/textures/app_icon.png IsFile /Users/jaxreiff/Documents/untitled/assets/textures/kitty.png IsFile /Users/jaxreiff/Documents/untitled/assets/test Created IsFile AttributeModified /Users/jaxreiff/Documents/untitled/assets/manifest.assets IsFile notify_events: Notifying events #: 4. /Users/jaxreiff/Documents/untitled/assets/textures/app_icon.png IsFile ...

...repeated ten or so times. From this, it seems that bevy_asset_loader is doing something to the assets folder during build that generates a filesystem event, which then triggers another build, and so on. Eventually the loop stops, after a varying amount of loops, my only explanation for which is that potentially the debouncing built into notify is breaking the loop.

Initially, I thought this may be related to notify-rs/notify#465 or watchexec/cargo-watch#242, but printing the filesystem events showed that the "AttributeModified" event is being triggered on the new file over and over again, which notify is probably correct to pick up.

My apologies if this issue belongs in another repository- unfortunately this appears to be a strange (potentially platform-specific) interaction between a number of dependencies so it is difficult to nail down.

Example repository: https://github.com/cxreiff/untitled

OS: macOS 13.2.1 CPU: (12) arm64 Apple M2 Max

NiklasEi commented 1 year ago

I cannot reproduce this on linux using your repository. Do you still see this issue without using dynamic assets?

cxreiff commented 1 year ago

This issue only occurs for me while using dynamic assets, however since opening this I have noticed related issues being discussed on the Trunk repository itself, which very well might resolve my issue: https://github.com/thedodd/trunk/issues/461 https://github.com/thedodd/trunk/pull/516

So I think I can resolve this in favor of that PR for now. I'll re-open if it turns out to be unrelated! Thank you for your time.