Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bevy 0.15 #38

Merged
merged 4 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ keywords = ["gamedev", "networking", "wasm", "bevy"]
license = "MIT OR Apache-2.0"
name = "bevy_web_asset"
repository = "https://github.com/johanhelsing/bevy_web_asset"
version = "0.9.0"
version = "0.10.0"

[dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_asset",
] }
pin-project = "1.1.5"

[features]
default = ["redirect"]
redirect = [] # enables surf::middleware::Redirect

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
surf = { version = "2.3", default-features = false, features = [
"h1-client-rustls",
Expand All @@ -32,10 +36,11 @@ wasm-bindgen = { version = "0.2", default-features = false }
wasm-bindgen-futures = "0.4"

[dev-dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_asset",
"bevy_core_pipeline",
"bevy_sprite",
"bevy_window", # https://github.com/bevyengine/bevy/issues/16568
"png",
"webgl2",
"x11", # GitHub Actions runners don't have libxkbcommon installed, so can't use Wayland
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ I intend to support the latest bevy release in the `main` branch.

|bevy|bevy_web_asset|
|----|--------------|
|0.14|0.9, main |
|0.15|0.10, main |
|0.14|0.9, |
|0.13|0.8 |
|0.12|0.7 |
|0.9 |0.5 |
Expand Down
10 changes: 4 additions & 6 deletions examples/web_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ fn main() {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());

commands.spawn(SpriteBundle {
// Simply use a url where you would normally use an asset folder relative path
texture: asset_server.load("https://s3.johanhelsing.studio/dump/favicon.png"),
..default()
});
commands.spawn(Sprite::from_image(
asset_server.load("https://s3.johanhelsing.studio/dump/favicon.png"),
));
}
11 changes: 8 additions & 3 deletions src/web_asset_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
}

#[cfg(not(target_arch = "wasm32"))]
async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
async fn get<'a>(path: PathBuf) -> Result<Box<dyn Reader>, AssetReaderError> {
use std::future::Future;
use std::io;
use std::pin::Pin;
Expand Down Expand Up @@ -114,7 +114,12 @@ async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
)
})?;

#[cfg(not(feature = "redirect"))]
let client = surf::Client::new();

#[cfg(feature = "redirect")]
let client = surf::Client::new().with(surf::middleware::Redirect::default());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, when surf::middleware::Redirect is added, web_image example errors with something like:

ERROR bevy_asset::server: Encountered an I/O error while loading asset: unexpected status code 500 while loading https://cdn.pixabay.com/photo/2015/03/10/17/23/youtube-667451_1280.png: Head byte length should be less than 8kb

Copy link
Owner

@johanhelsing johanhelsing Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in a recent PR (#37), @soraxas what do you think? Won't this break redirecting for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related surf issue: http-rs/surf#289

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have encountered status code 500 but that was due to bot prevention arise from the meta check; after disabling meta check I have not had that issue.

I'm currently away from my machine; I can test our the PR later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a feature flag for the redirect middleware. defaulting to redirect preserves the original behavior.

running the example with cargo run --example web_image --no-default-features resolves the error.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a good compromise. Wish the http client library situation in rust was better.


let mut response = ContinuousPoll(client.get(str_path)).await.map_err(|err| {
AssetReaderError::Io(
io::Error::new(
Expand Down Expand Up @@ -155,11 +160,11 @@ impl AssetReader for WebAssetReader {
fn read<'a>(
&'a self,
path: &'a Path,
) -> impl ConditionalSendFuture<Output = Result<Box<Reader<'a>>, AssetReaderError>> {
) -> impl ConditionalSendFuture<Output = Result<Box<dyn Reader>, AssetReaderError>> {
get(self.make_uri(path))
}

async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<Box<Reader<'a>>, AssetReaderError> {
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<Box<dyn Reader>, AssetReaderError> {
match self.make_meta_uri(path) {
Some(uri) => get(uri).await,
None => Err(AssetReaderError::NotFound(
Expand Down
Loading