ScanMountGoat / image_dds

Convert images to and from compressed DDS formats
MIT License
7 stars 2 forks source link

Panic in img2ddsf32 when using Rgba16Float #14

Closed zhouhang95 closed 2 months ago

zhouhang95 commented 2 months ago

Defualt format is ok, but when i try Rgba32Float format, get panic.

        _ => image_dds::dds_from_imagef32(
            &image,
            image_dds::ImageFormat::Rgba32Float,
            image_dds::Quality::Fast,
            image_dds::Mipmaps::GeneratedAutomatic,
        )
        .unwrap(),
thread 'main' panicked at C:\Users\zhouhang\.cargo\registry\src\rsproxy.cn-0dccff568467c15b\bytemuck-1.15.0\src\allocation.rs:200:44:
called `Result::unwrap()` on an `Err` value: AlignmentMismatch
stack backtrace:
   0:     0x7ff7f6531e92 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff7f6547e3d - core::fmt::rt::Argument::fmt
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\fmt\rt.rs:142
   2:     0x7ff7f6547e3d - core::fmt::write
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\fmt\mod.rs:1120
   3:     0x7ff7f652f7e1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\io\mod.rs:1846
   4:     0x7ff7f6531cba - std::sys_common::backtrace::_print
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff7f6531cba - std::sys_common::backtrace::print
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff7f6533e69 - std::panicking::default_hook::closure$1
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:272
   7:     0x7ff7f6533b25 - std::panicking::default_hook
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:292
   8:     0x7ff7f6534384 - std::panicking::rust_panic_with_hook
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:781
   9:     0x7ff7f6534259 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:659
  10:     0x7ff7f6532539 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\sys_common\backtrace.rs:171
  11:     0x7ff7f6533f26 - std::panicking::begin_panic_handler
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:647
  12:     0x7ff7f65546e7 - core::panicking::panic_fmt
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\panicking.rs:72
  13:     0x7ff7f6554d23 - core::result::unwrap_failed
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\result.rs:1649
  14:     0x7ff7f6021035 - enum2$<core::result::Result<alloc::vec::Vec<u8,alloc::alloc::Global>,bytemuck::PodCastError> >::unwrap
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\result.rs:1073
  15:     0x7ff7f6021035 - bytemuck::allocation::cast_vec<half::binary16::f16,u8>
                               at C:\Users\zhouhang\.cargo\registry\src\rsproxy.cn-0dccff568467c15b\bytemuck-1.15.0\src\allocation.rs:200
  16:     0x7ff7f6018790 - core::ops::function::FnOnce::call_once<alloc::vec::Vec<u8,alloc::alloc::Global> (*)(alloc::vec::Vec<half::binary16::f16,alloc::alloc::Global>),tuple$<alloc::vec::Vec<half::binary16::f16,alloc::alloc::Global> > >
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\ops\function.rs:250
  17:     0x7ff7f601da40 - enum2$<core::result::Result<alloc::vec::Vec<half::binary16::f16,alloc::alloc::Global>,enum2$<image_dds::error::SurfaceError> > >::map<alloc::vec::Vec<half::binary16::f16,alloc::alloc::Global>,enum2$<image_dds::error::SurfaceError>,alloc::vec::Vec<u8,alloc
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\result.rs:746
  18:     0x7ff7f60240c7 - image_dds::encode::impl$7::encode
                               at D:\image_dds\image_dds\src\encode.rs:408
  19:     0x7ff7f60202f9 - image_dds::encode::MipData<f32>::encode<f32>
                               at D:\image_dds\image_dds\src\encode.rs:173
  20:     0x7ff7f601fbd9 - image_dds::encode::encode_mipmaps_rgba<image_dds::surface::SurfaceRgba32Float<ref$<slice2$<f32> > >,f32>
                               at D:\image_dds\image_dds\src\encode.rs:115
  21:     0x7ff7f601f8c9 - image_dds::encode::encode_surface<image_dds::surface::SurfaceRgba32Float<ref$<slice2$<f32> > >,f32>
                               at D:\image_dds\image_dds\src\encode.rs:72
  22:     0x7ff7f60182dc - image_dds::surface::SurfaceRgba32Float<ref$<slice2$<f32> > >::encode<ref$<slice2$<f32> > >
                               at D:\image_dds\image_dds\src\encode.rs:41
  23:     0x7ff7f601756c - image_dds::dds::dds_from_imagef32
                               at D:\image_dds\image_dds\src\dds.rs:50
  24:     0x7ff7f6014dbf - img2ddsf32::main
                               at D:\image_dds\image_dds\examples\img2ddsf32.rs:33
  25:     0x7ff7f6015c2b - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\ops\function.rs:250
  26:     0x7ff7f60125fe - core::hint::black_box
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\hint.rs:334
  27:     0x7ff7f60125fe - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\std\src\sys_common\backtrace.rs:155
  28:     0x7ff7f6015b31 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\std\src\rt.rs:166
  29:     0x7ff7f652ade2 - std::rt::lang_start_internal::closure$2
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\rt.rs:148
  30:     0x7ff7f652ade2 - std::panicking::try::do_call
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:554
  31:     0x7ff7f652ade2 - std::panicking::try
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:518
  32:     0x7ff7f652ade2 - std::panic::catch_unwind
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panic.rs:142
  33:     0x7ff7f652ade2 - std::rt::lang_start_internal
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\rt.rs:148
  34:     0x7ff7f6015b0a - std::rt::lang_start<tuple$<> >
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\std\src\rt.rs:165
  35:     0x7ff7f6015759 - main
  36:     0x7ff7f65528d8 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  37:     0x7ff7f65528d8 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  38:     0x7ffe300a257d - BaseThreadInitThunk
  39:     0x7ffe3180aa48 - RtlUserThreadStart
ScanMountGoat commented 2 months ago

What file type and image format are you using as the input? This looks like an alignment issue from some casts that are performed internally. I should be able to do this efficiently without bytemuck to avoid any potentially confusing panics.

ScanMountGoat commented 2 months ago

I'm able to reproduce this on my end and should be able to implement a fix.