katharostech / bevy_retrograde

Plugin pack for making 2D games with Bevy
Other
296 stars 9 forks source link

Problem with the Ldtk loader when running from another project #64

Closed LeCalicot closed 2 years ago

LeCalicot commented 2 years ago

Hi,

first, thanks for the great work, it looks promising! I'm new to bevy and rust, thanks for your patience. I was trying to adapt the ldtk map loading for my project and I encountered some issues. I think it's a bug, but not 100% sure.

First, to test it, I ran the actual ldtk_map.rs example from the cloned repo, it works fine. Then, I moved the example to main.rs. It still compiles fine. Then, I also linked to the online crates what I could.

At this point I have:

[package]
...
name = "bevy_retrograde"
...

[features]
default = ['ldtk']
ldtk = ["bevy_retrograde_ldtk"]

[dependencies]
bevy = {version = "0.5", default-features = false}

bevy_retrograde_core = {version = "0.2"}
bevy_retrograde_ldtk = {version = "0.2", optional = true}
bevy_retrograde_macros = {version = "0.2"}
hex = "0.4.3"

[dev-dependencies]
hex = "0.4.3"
rand = "0.8.3"

[profile.dev]
debug = 0
opt-level = 1

that I can run with cargo run. This runs fine. The _bevyretrograde is still loaded from the lib.rs !

Then I copy the exact same code (main.rs and Cargo.toml) to my project. The difference is that the lib.rs is not present, so I add the line: bevy_retrograde = "0.2" in the Cargo.toml file.

But somehow running the same code from my project, it still compiles fine, but when running it, it panics:

Finished dev [unoptimized] target(s) in 26.22s Runningtarget/debug/my_project Oct 02 21:25:26.869 WARN bevy_asset::asset_server: noAssetLoaderfound for the following extension: ldtk thread 'Compute Task Pool (4)' panicked at 'Requested resource does not exist: bevy_asset::assets::Assets<bevy_retrograde_ldtk::asset::LdtkMap>', /home/luc/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.5.0/src/system/system_param.rs:244:17 note: run withRUST_BACKTRACE=1environment variable to display a backtrace thread 'main' panicked at 'task has failed', /home/luc/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.0.3/src/task.rs:368:45

However, if I copy the lib.rs from the repo, it compiles and run fine (all the code is identical, so...yeah, makes sense ^^) if I include the lib:

[lib]
name = "bevy_retrograde"
path = "src/lib.rs"

Am I missing something or is there an issue with loading the ldtk plugin from the crate?

zicklag commented 2 years ago

Hey there!

Sorry for the delay, I've been unavailable for the last bit, but I'm going to test this out and see why it's not working as soon as I can. It should be a simple fix, one way or the other.

zicklag commented 2 years ago

I think I know what the problem is now. When creating a standalone project, you aren't meant to depend on the individual bevy_retrograde_[something] crates by themselves. You only need to depend on the bevy_retrograde crate. The bevy_retrograde crate is the one responsible for enabling certain Bevy plugins, which is why you are getting the panic.

I created a new project from scratch and created a GitHub gist with the Cargo.toml and main.rs file that I used and it worked fine. Let me know if this doesn't work for you!

https://gist.github.com/zicklag/06f7bd82afa81bc8f45b4e92ab866658

LeCalicot commented 2 years ago

That did the trick! Thanks for the help!