MvxImageView.SetImageBitmap causing "Memory violation" - xamarin.android

I have built an app in iOS and now building the app in Android. I'm basically done with the app but I'm running into a pretty consistent problem in the app. I will be going through the app hitting various pages when the app crashes. It seems to be pretty random and appears to be a memory issue. Each "page" has maybe 0-2 images on the page, but nothing major (small png files). I'm using a combination of android ImageView and MvxImageView. I'm setting the MvxImageView through binding ImageUrl like this:
local:MvxBind="ImageUrl CurrencyImage"
Here is the exception I get:
[mono-rt] Stacktrace:
[mono-rt]
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a (intptr,intptr&,intptr,intptr,intptr,Java.Interop.JniArgumentValue*) <0x0005b>
[mono-rt] at Java.Interop.JniEnvironment/InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference,Java.Interop.JniObjectReference,Java.Interop.JniMethodInfo,Java.Interop.JniArgumentValue*) [0x0008f] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12079
[mono-rt] at Java.Interop.JniPeerMembers/JniInstanceMethods.InvokeVirtualVoidMethod (string,Java.Interop.IJavaPeerable,Java.Interop.JniArgumentValue*) [0x00068] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:31
[mono-rt] at Android.Widget.ImageView.SetImageBitmap (Android.Graphics.Bitmap) [0x0002c] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Widget.ImageView.cs:1026
[mono-rt] at MvvmCross.Binding.Droid.Views.MvxImageView.SetImageBitmap (Android.Graphics.Bitmap) <IL 0x00032, 0x0019b>
[mono-rt] at MvvmCross.Binding.Droid.Views.MvxImageView/<>c__DisplayClass19_0.<ImageHelperOnImageChanged>b__0 () <IL 0x00011, 0x000b7>
[mono-rt] at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/3819/96c7ba6c/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
[mono-rt] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Java.Lang.IRunnable.cs:81
[mono-rt] at (wrapper dynamic-method) object.037ff22d-dd39-45fa-8726-c673a7d6897c (intptr,intptr) <IL 0x00011, 0x0003b>
[mono-rt] at (wrapper native-to-managed) object.037ff22d-dd39-45fa-8726-c673a7d6897c (intptr,intptr) <IL 0x00021, 0x000ef>
And here is the audit I see in DDMS:
10-13 17:26:06.213: E/audit(2793): type=1701 msg=audit(1476393966.213:869): auid=4294967295 uid=10198 gid=10198 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=14236 comm="APPNAME.droid" reason="memory violation" sig=11
Any help would be greatly appreciated. When I say consistent above, basically within 30 seconds of "hammering" around in the app something happens.
Devices: Most of testing on Samsung Galaxy Tab A and that's from exception above. Also have tested on older LG phone and latest Nexus. LG phone gets same error. Latest Nexus I have gotten the error but not as consistent. I can be on the app for a while sometimes with no issues.

While this didn't fix my issue with MvxImageView, I tried Picasso. I created a PicassoImageView object and created a public "ImageURL" that allowed me to still use the MvvmCross binding. I haven't seen the error since.

Related

Unable to deploy Xamarin Froms iOS App it just keeps breaking on physical device

this is the first time I'm trying to write a request to you. Normaly I had could resolve most of the problems thanks to stackoverflow and others.
I developed an Xamarin.Forms App which runs on Android perfectly but when I try to deploy it to iOS (physical iPhone 8) it keeps breaking.
After searching for hours and trying diffrent things I hope someone can read out of the Code whats the matter...
I tried as well to set breakpoints in the appdelegate or first Page but after some seconds everthing breaks with this information:
2021-08-27 18:39:24.004 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 6
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Processing: 'start profiler: no'
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Profiler not loaded (disabled)
Loaded assembly: /private/var/containers/Bundle/Application/092BCD0C-2FC9-4F1B-A83E-29D87ACD245E/SHAPP.iOS.app/Xamarin.iOS.dll [External]
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Xamarin.Forms.Core.dll [External]
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/FFImageLoading.Platform.dll [External]
....
[0:] Failed to force load assembly /var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Forms9Patch.dll. Type:Forms9Patch.PopupLayerEffect. Exception: 'You must call Xamarin.Forms.Forms.Init(); prior to using this property.'. Callstack: ' at Xamarin.Forms.Device.get_PlatformServices () [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:87
at Xamarin.Forms.Device.GetAssemblies () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:245
at Xamarin.Forms.DependencyService.Initialize () [0x00021] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:103
at Xamarin.Forms.DependencyService.Get[T] (Xamarin.Forms.DependencyFetchTarget fetchTarget) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:28
at Forms9Patch.Settings.ConfirmInitialization () [0x00008] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Models\Settings.cs:116
at Forms9Patch.PopupLayerEffect..cctor () [0x00000] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Effects\PopupLayerEffect.cs:19 '
...
[0:] An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
at UIKit.UIResponder..ctor (Foundation.NSObjectFlag t) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIResponder.g.cs:74
at UIKit.UIView..ctor (Foundation.NSObjectFlag t) [0x00000] in
...
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at SHAPP.iOS.Application.Main (System.String[] args) [0x00001] in C:\VisualCSharp\MyProjects\SHAPP\SHAPP.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Die App wurde beendet.
Thanks Jason and Saamer,
as you wrote i did try to fix that error prior to my request. But I could not find a way.
My AppDelegate looks like that:
using Foundation;
using Lottie.Forms.Platforms.Ios;
using UIKit;
namespace SHAPP.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Xamarin.Forms.Forms.Init();
Forms9Patch.iOS.Settings.Initialize(this);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
// ObjCRuntime.Class.ThrowOnInitFailure = false;
LoadApplication(new App());
//AnimationViewRenderer.Init();
return base.FinishedLaunching(app, options);
}
}
}
So nothing to special, I did even try to set the old Lottie Init, but it did not help. As well I tryed to cancel all nuget Lottiefiles in iOS and to reinstall them, afterwards I cleaned the projects and restartet the build, same error.
Only working thing is to completly cancel Lottieusage.
The Lottie-XAML I use look's like that:
<lottie:AnimationView
Animation="14525-plumbers.json"
AutoPlay="True"
RepeatCount="3"
RepeatMode="Restart"
CacheComposition="True"
HeightRequest="500"
VerticalOptions="Start"
HorizontalOptions="Center"
IsVisible="true"
/>
If I comment it out everything works fine.
The LottieAnimationfile is in my RessourcesFolder (BundledRessource) as well as in the main folder.
Folders iOS and LottieFiles
Gentlement any ideas, what could be wrong? Thanks in advance
As Jason mentioned, you need to add that line in the AppDelegate, as you can see in this example
But you have another error too as you can read the error message at the end of the StackTrace you shared:
An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
What Lottie package are you using? Is it this one? Are you using the latest version?
You have to make sure that you add the iOS version of the Lottie package to the iOS project.

Oculus Lip sync IOS support

I have made an app which is using audio lip sync and it runs fine on android, and mac but when I build it for iOS it is keep giving me this error:
DllNotFoundException: Unable to load DLL 'OVRLipSync': The specified
module could not be found. at OVRLipSync.ovrLipSyncDll_Initialize
(Int32 samplerate, Int32 buffersize) [0x00000] in :0
at OVRLipSync.Initialize (Int32 sampleRate, Int32 bufferSize)
[0x00000] in :0 at OVRLipSync.Awake () [0x00000]
in :0 (Filename: currently not available on
il2cpp Line: -1)
Is this a known issue?? or any new bug in the latest package??
As it turns out Oculus Lip Sync doesn't support iOS yet and they don't plan to do it in the near future.
Hope it helps someone else.

MvvmCross sometimes has problems with IoC

I encounter quite bad problem with MvvmCross IoC resolving.
We have a big application that registers about 100 different services and 6 plugins.
Sometimes we are getting problems with resolving these services. Most time it works fine, but then at Xamarin.Insights I can see that at production, there are some problems that happens(NOT ALWAYS), for example this:
Cirrious.CrossCore.Exceptions.MvxIoCResolveExceptionFailed to resolve
type Cirrious.MvvmCross.Localization.IMvxTextProvider
Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve(Type)
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve<Cirrious.MvvmCross.Localization.IMvxTextProvider> () <0x00023>
at Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.Localization.IMvxTextProvider> () <0x0004b>
<project>.Droid.Code.Menu.MenuActivity<TextMessageDetailsViewModel>.OnCreate(Bundle)
Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(intptr, intptr, intptr)
at (wrapper dynamic-method) object.715a16ed-a35e-4884-89f1-5e2568dbe846 (intptr,intptr,intptr) <0x00043>
What can cause the problem that only sometimes it doesn't work?

iOS black screen and MissingMethodException: Method not found: 'System.Type.op_Equality'

I'm starting to create an app using MvvmCross. So far I have an version for Android and for WP running. Unfortunately, creating the app for iOS isn't easy. When running the iOS-app in the simulator, I only get a black screen. In MonoDevelop's Application Output is see the following exception:
2013-01-07 10:42:20.506 BestSellersTouch[319:21e03] mvx: Diagnostic: 0.09 Exception masked MissingMethodException: Method not found: 'System.Type.op_Equality'.
at Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.CreateView (Cirrious.MvvmCross.Views.MvxShowViewModelRequest request) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.Show (Cirrious.MvvmCross.Views.MvxShowViewModelRequest request) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxTouchViewDispatcher+<>c__DisplayClass4.<RequestNavigate>b__3 () [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxTouchUIThreadDispatcher+<>c__DisplayClass1.<InvokeOrBeginInvoke>b__0 () [0x00000] in <filename unknown>:0
2013-01-07 10:42:20.508 BestSellersTouch[319:21e03] Application windows are expected to have a root view controller at the end of application launch
Is this error causing a black screen?
References to System.Type.op_Equality only exists when an assembly is compiled against mscorlib.dll 4.0 (and later).
Current version of MonoTouch does not support 4.0 (and that member is not part of the assembly) which result in this exception at runtime.
The solution, until MonoTouch supports 4.0 (this spring) is to rebuild the assembly and make sure it referenes the mscorlib.dll that ships with MonoTouch.
The fact that this exception is thrown while presenting a view is likely the reason of your black screen (nothing got executed to show anything on it).

Issues with MonoTouch and CFStream API

I am currently developing an application that needs to communicate with a MQTT server via a socket connection. As the System.Net.Sockets API tends to misbehave when switching from a WiFi network to a 3G network (and this happens quite a lot actually) I've decided to give the CFStream API a try. In doing so I've encountered several issues, as follows.
Creating a pair of streams with CreatePairWithSocketToHost crashes the application as soon as I call Open() on either one of the streams.
CFStream.CreatePairWithSocketToHost(GetEndPoint(), out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
The crash occurs regardless of whether I call EnableEvents() or not. The exception is:
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.CoreFoundation.CFException: The operation couldn’t be completed. Cannot allocate memory
at MonoTouch.CoreFoundation.CFStream.CheckError () [0x0000f] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:236
at MonoTouch.CoreFoundation.CFStream.Open () [0x00040] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:248
at TestCfNework.RootViewController.TestCreatePairToHost () [0x00041] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:79
at TestCfNework.RootViewController.ViewDidLoad () [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:24
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124
at TestCfNework.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0002e] in /Users/adrian/Projects/TestCfNework/TestCfNework/AppDelegate.cs:32
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at TestCfNework.Application.Main (System.String[] args) [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/Main.cs:17
Creating a pair of streams with CreatePairWithSocket by first creating and connecting a CFSocket allows for Open() to proceed without crashing, but CanAcceptBytesEvent is never fired, CanAcceptBytes() is always false and any write attempt fails with a timeout.
mSocket = new CFSocket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp,
CFRunLoop.Current);
mSocket.ConnectEvent += delegate {
Console.WriteLine("Socket connected");
CFStream.CreatePairWithSocket(mSocket, out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
mWriteStream.CanAcceptBytesEvent += delegate {
Console.WriteLine("Write stream can now accept data");
};
mWriteStream.ErrorEvent += delegate {
Console.WriteLine(mWriteStream.GetError());
};
};
mSocket.Connect(GetEndPoint(), 0);
Creating a pair of streams using CreatePairWithPeerSocketSignature is the only one that actually produces a pair of streams that I can work with: opening does not crash and I am allowed to write to and read from respectively.
The API behaves this way both on the simulator and on the actual device. So, is this something I am doing wrong? Is it a MonoTouch issue? Is it a bug in the CFStream API itself?
MonoTouch version: 6.0.1.
XCode version: 4.5.
I wrote most the CFNetwork code in MonoMac / MonoTouch, so I should hopefully be able to help you with this :-)
Your code looks ok to me. It works fine with MonoMac (stand-alone Cocoa application on the Mac), but I see the same problem with MonoTouch. Opening the read stream sometimes works, sometimes not, opening the write stream always fails.
CFStream.CreatePairWithSocketToHost() calls CFStreamCreatePairWithSocketToCFHost().
After adding a new overloaded version:
public static void CreatePairWithSocketToHost (string host, int port,
out CFReadStream readStream,
out CFWriteStream writeStream)
which calls CFStreamCreatePairWithSocketToHost(), this is now working fine.
I just had a look at this and found the problem, will have a fix for it shortly.
About your second problem, the CFSocket API is hitting the same code path internally, so it's also affected by this bug.
To wake up the 3G network, you want to use:
http://iosapi.xamarin.com/?link=T%3aMonoTouch.ObjCRuntime.Runtime%2fM%2fStartWWAN

Resources