Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

#148 fixed sigsegv crashes #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class MvxAndroidLocalFileImageLoader
{
private const string ResourcePrefix = "res:";

private readonly IDictionary<CacheKey, WeakReference<Bitmap>> _memCache =
new Dictionary<CacheKey, WeakReference<Bitmap>>();
//private readonly IDictionary<CacheKey, WeakReference<Bitmap>> _memCache =
// new Dictionary<CacheKey, WeakReference<Bitmap>>();

public async Task<MvxImage<Bitmap>> Load(string localPath, bool shouldCache, int maxWidth, int maxHeight)
{
Expand Down Expand Up @@ -166,31 +166,31 @@ private static int CalculateInSampleSize(BitmapFactory.Options options, int reqW

private bool TryGetCachedBitmap(string localPath, int maxWidth, int maxHeight, out Bitmap bitmap)
{
var key = new CacheKey(localPath, maxWidth, maxHeight);
WeakReference<Bitmap> reference;
//var key = new CacheKey(localPath, maxWidth, maxHeight);
//WeakReference<Bitmap> reference;

if (_memCache.TryGetValue(key, out reference))
{
Bitmap target;
if (reference.TryGetTarget(out target) && target != null && target.Handle != IntPtr.Zero && !target.IsRecycled)
{
bitmap = target;
return true;
}
//if (_memCache.TryGetValue(key, out reference))
//{
// Bitmap target;
// if (reference.TryGetTarget(out target) && target != null && target.Handle != IntPtr.Zero && !target.IsRecycled)
// {
// bitmap = target;
// return true;
// }

_memCache.Remove(key);
}
// _memCache.Remove(key);
//}

bitmap = null;
return false;
}

private void AddToCache(string localPath, int maxWidth, int maxHeight, Bitmap bitmap)
{
if (bitmap == null) return;
//if (bitmap == null) return;

var key = new CacheKey(localPath, maxWidth, maxHeight);
_memCache[key] = new WeakReference<Bitmap>(bitmap);
//var key = new CacheKey(localPath, maxWidth, maxHeight);
//_memCache[key] = new WeakReference<Bitmap>(bitmap);
}

private class CacheKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class MvxDynamicImageHelper<T>
: IMvxImageHelper<T>
where T : class
{
private readonly IMvxMainThreadDispatcher _dispatcher;

#region ImageState enum

public enum ImageState
Expand All @@ -31,6 +33,11 @@ public enum ImageState

#endregion ImageState enum

public MvxDynamicImageHelper(IMvxMainThreadDispatcher dispatcher)
{
_dispatcher = dispatcher;
}

private ImageState _currentImageState = ImageState.DefaultShown;

private CancellationTokenSource _cancellationSource;
Expand Down Expand Up @@ -103,7 +110,7 @@ public void Dispose()
private void FireImageChanged(T image)
{
var handler = ImageChanged;
handler?.Invoke(this, new MvxValueEventArgs<T>(image));
_dispatcher.RequestMainThreadAction(() => handler?.Invoke(this, new MvxValueEventArgs<T>(image)));
}

private async Task RequestImageAsync(string imageSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public Timer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan pe
{
if (IsCancellationRequested)
break;
Task.Run(() => tuple.Item1(tuple.Item2));
await Task.Run(() => tuple.Item1(tuple.Item2));
await Task.Delay(period);
}
}, Tuple.Create(callback, state), CancellationToken.None,
Expand Down