mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-21 06:50:43 +01:00
Save size check: skip orphan baked sets, clearer message, wider test
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
52505ecbc2
commit
b99ebf7321
2 files changed
+14
-5
No files matched your search
@@ -139,7 +139,8 @@ fn load_size(pf: &ProjectFile) -> Result<u64> {
|
||||
let tiles = |img: &TileImage| (img.allocated_count() as u64) * (TILE_AREA * img.comps() * 2) as u64;
|
||||
n += pf.pixels.layers.iter().filter(|((id, _), _)| texture_set_of(&pf.project, *id).is_some()).map(|(_, img)| tiles(img)).sum::<u64>();
|
||||
n += pf.pixels.masks.iter().filter(|(id, _)| texture_set_of(&pf.project, **id).is_some()).map(|(_, img)| tiles(img)).sum::<u64>();
|
||||
for maps in pf.baked.values() {
|
||||
// `load` skips the baked maps of a texture set that no longer exists.
|
||||
for maps in pf.baked.iter().filter(|(ts, _)| **ts < pf.project.texture_sets.len()).map(|(_, m)| m) {
|
||||
for (m, data) in &maps.maps {
|
||||
let h = maps.height(*m);
|
||||
if h != 0 && data.len() == (maps.resolution as usize) * (h as usize) * m.components() {
|
||||
@@ -156,8 +157,8 @@ fn check_loadable(pf: &ProjectFile, limit: u64) -> Result<()> {
|
||||
if size > limit {
|
||||
let gib = |b: u64| b as f64 / (1u64 << 30) as f64;
|
||||
return Err(FormatError::TooLarge(format!(
|
||||
"the project holds {:.1} GiB of data once unpacked, but TextureCraft opens project files only up to {:.1} GiB, so it was not saved and the file on disk is unchanged. \
|
||||
Remove paint layers or baked maps, or lower the texture resolution",
|
||||
"the project holds {:.2} GiB of data once unpacked, but TextureCraft opens project files only up to {:.2} GiB, so nothing was saved and an existing file is unchanged. \
|
||||
Remove paint layers or baked maps to make it smaller",
|
||||
gib(size),
|
||||
gib(limit)
|
||||
)));
|
||||
|
||||
@@ -219,7 +219,15 @@ fn load_size_matches_what_load_counts() {
|
||||
tiled.project.texture_sets[0].uv_tiles = vec![1001, 1002];
|
||||
tiled.pixels = PixelStore::default();
|
||||
tiled.baked = [(0, BakedMaps { resolution: 32, maps: [(BakedMap::AmbientOcclusion, Arc::new(vec![0.25; 32 * 16]))].into() })].into();
|
||||
for pf in [&s.pf, &tiled] {
|
||||
// The branches where the count could drift: pixels of a layer in no stack, a baked map of a
|
||||
// set that does not exist, and a baked map whose size does not match (not written).
|
||||
let mut odd = sample().pf;
|
||||
odd.pixels.layer_mut(LayerId(999), Channel::BaseColor, (128, 128)).set(1, 1, &[1, 2, 3, 4]);
|
||||
odd.pixels.mask_mut(LayerId(998), (64, 64)).set(1, 1, &[1, 2]);
|
||||
odd.baked.insert(7, BakedMaps { resolution: 16, maps: [(BakedMap::AmbientOcclusion, Arc::new(vec![0.5; 256]))].into() });
|
||||
odd.baked.entry(1).or_default().resolution = 8;
|
||||
odd.baked.get_mut(&1).unwrap().maps.insert(BakedMap::Curvature, Arc::new(vec![0.5; 13]));
|
||||
for pf in [&s.pf, &tiled, &odd] {
|
||||
let bytes = save_project_bytes(pf).unwrap();
|
||||
let (_, counted) = load_counted(Cursor::new(bytes)).unwrap();
|
||||
assert!(counted > 1000);
|
||||
@@ -234,7 +242,7 @@ fn a_project_too_big_to_reopen_is_not_saved() {
|
||||
assert!(check_loadable(&s.pf, size).is_ok());
|
||||
let err = check_loadable(&s.pf, size - 1).unwrap_err();
|
||||
assert!(matches!(err, FormatError::TooLarge(_)));
|
||||
assert!(err.to_string().contains("not saved"), "{err}");
|
||||
assert!(err.to_string().contains("nothing was saved"), "{err}");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
Reference in new issue
Block a user