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

Cannot load textures bigger than 512MB #5304

Closed
fgiordana opened this issue Jul 13, 2022 · 3 comments
Closed

Cannot load textures bigger than 512MB #5304

fgiordana opened this issue Jul 13, 2022 · 3 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@fgiordana
Copy link
Contributor

Bevy version

commit - de484c1

[Optional] Relevant system information

MacOs 12.4, MacBook Pro Apple M1 Max

What you did

I tried loading a PNG texture larger than 512MB.

What went wrong

It failed loading with the following warning:
2022-07-13T03:37:38.679032Z WARN bevy_asset::asset_server: encountered an error while loading an asset: You may need to add the feature for the file format: failed to load an image: Insufficient memory

Additional information

This is due to the use of a helper function from the image crate, which sets default limits on allocation (512MB).

(from bevy's texture/image.rs:384)

let dyn_img = image::load_from_memory_with_format(buffer, image_crate_format)?;

it can be fixed by using a Reader instead:

let mut reader = image::io::Reader::new(std::io::Cursor::new(buffer));
reader.set_format(image_crate_format);
reader.no_limits();
let dyn_img = reader.decode()?;

With this fix I was able to load very large textures (1GB+) successfully

@fgiordana fgiordana added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jul 13, 2022
@superdump
Copy link
Contributor

Is that 512MB the compressed file size? What image dimensions? What format?

@fgiordana
Copy link
Contributor Author

That is the max allocation size allowed for the decoder, so the answer depends on the decoder.
Instead of using that utility function it is possible to use the more advanced Reader that can be configured ad hoc.

In my case I need to load a 16k texture resulting from a photogrammetry scan, this fix allows me to load unlimited size textures (until the actual memory runs out)

@Nilirad Nilirad added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Jul 13, 2022
@superdump
Copy link
Contributor

I guess as we handle the error state anyway, if you try to load a texture that is too large for whatever reason and you have insufficient ram, the APIs will warn you appropriately. From that perspective it seems fine.

@bors bors bot closed this as completed in 052de08 Jul 13, 2022
inodentry pushed a commit to IyesGames/bevy that referenced this issue Aug 8, 2022
# Objective

Fixes bevyengine#5304 

## Solution

Instead of using a simple utility function for loading, which uses a default allocation limit of 512MB, we use a Reader object which can be configured ad hoc.

## Changelog

> This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section.

- Allows loading of textures larger than 512MB
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

Fixes bevyengine#5304 

## Solution

Instead of using a simple utility function for loading, which uses a default allocation limit of 512MB, we use a Reader object which can be configured ad hoc.

## Changelog

> This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section.

- Allows loading of textures larger than 512MB
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes bevyengine#5304 

## Solution

Instead of using a simple utility function for loading, which uses a default allocation limit of 512MB, we use a Reader object which can be configured ad hoc.

## Changelog

> This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section.

- Allows loading of textures larger than 512MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants