According to Microsoft, this is the correct way to load an image
Assembly assembly = GetType().GetTypeInfo().Assembly;
using Stream stream = assembly.GetManifestResourceStream("Ringotan.KanjiControl.Resources.next_arrow.png");
_arrowImage = PlatformImage.FromStream(stream);
This works perfectly in Debug. However, in Release it causes the entire app to crash with the native exception
[libc.so] __memcpy_aarch64_simd
SIGSEGV
backtrace:
#00 pc 0x0000000000058158 /apex/com.android.runtime/lib64/bionic/libc.so (__memcpy_aarch64_simd+280)
#01 pc 0x000000000065bd04 /system/lib64/libhwui.so ((anonymous namespace)::FrontBufferedStream::read(void*, unsigned long) (.__uniq.259476571162685252206752541612201816602)+340)
#02 pc 0x000000000065bd60 /system/lib64/libhwui.so ((anonymous namespace)::FrontBufferedStream::peek(void*, unsigned long) const (.__uniq.259476571162685252206752541612201816602)+48)
#03 pc 0x00000000005b4168 /system/lib64/libhwui.so (SkCodec::MakeFromStream(std::__1::unique_ptr<SkStream, std::__1::default_delete<SkStream>>, SkSpan<SkCodecs::Decoder const>, SkCodec::Result*, SkPngChunkReader*, SkCodec::SelectionPolicy)+120)
because it's a native crash, there's no way to catch it or handle it gracefully.
Is there any way to fix this? If not, is there a better way to load an IImage
?
Notes:
I was able to work around (but not fix) the issue by not loading the image from a separate assembly, and not loading the image using GetManifestResourceStream
. I'm not sure which of those two are necessary.
Resources/next_arrow.png
from class library to main app project (under Resources/Images/next_arrow.png
). The Build Action should be "MauiAsset"Application.Context.Assets.Open("Resources/Images/next_arrow.png")
.File.Open( Path.Combine(NSBundle.MainBundle.ResourcePath, "Resources/Images/next_arrow.png"))
, but don't quote me on that because I started the iOS port yet)