Marino Milak
Marino Milak

Reputation: 31

Wp 8.1 app crashing when its not connected to debugger

Application works when its connected to PC and run with debugger. The problem starts when I disconnect phone from PC, run app from phone and try to open gallery and set image to image control. I tried to write error in a file on try/catch but catch is never called, like there is no error on app executing.

This is code where i select img:

private async void galleryBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FileOpenPicker filePicker = new FileOpenPicker();
                filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                filePicker.ViewMode = PickerViewMode.Thumbnail;

                // Filter to include a sample subset of file types
                filePicker.FileTypeFilter.Clear();
                filePicker.FileTypeFilter.Add(".bmp");
                filePicker.FileTypeFilter.Add(".png");
                filePicker.FileTypeFilter.Add(".jpeg");
                filePicker.FileTypeFilter.Add(".jpg");

                filePicker.PickSingleFileAndContinue();
                view.Activated += viewActivated;

            }
            catch (Exception err)
            {
                string error = err.StackTrace.ToString();
                await saveStringToLocalFile("test11", error);
            }
        }

And than it goes to :

 private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            try
            {
                FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

                if (args != null)
                {
                    if (args.Files.Count == 0) return;

                    view.Activated -= viewActivated;
                    StorageFile storageFile = args.Files[0];
                    var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(stream);

                    var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                    var obj = App.Current as App;
                    obj.ImageToEdit = bitmapImage;
                    obj.fileTransfer = storageFile;
                    checkTorch = -1;
                    await newCapture.StopPreviewAsync();
                    Frame.Navigate(typeof(EditImage));
                }
            }
            catch (Exception err) {
                string error = err.StackTrace.ToString();
                await saveStringToLocalFile("test11", error);
            }
        }

When img is selected i open screen for image editing and run this

 protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {

                var obj = App.Current as App;
                slika = obj.ImageToEdit;
                original = obj.ImageToEdit;
                ImagePreview.Source = slika;
                RotateTransform myRotateTransform = new RotateTransform();
                myRotateTransform.Angle = 0;
                ImagePreview.RenderTransform = myRotateTransform;
                var localSettings = ApplicationData.Current.LocalSettings;
            }
            catch (Exception err)
            {
                string error = err.StackTrace.ToString();
                await saveStringToLocalFile("test11", error);
            }

        }

That is all, any advice is appreciated;

Upvotes: 0

Views: 83

Answers (2)

leon karabchesvky
leon karabchesvky

Reputation: 501

In order to catch unhandled exceptions you can use a global exception catcher, in App.xaml.cs file define:

public App()
{
   this.InitializeComponent();
   this.Suspending += this.OnSuspending;
   this.UnhandledException += UnhandledExceptionHandler;
}

private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
   log.Critical(e.Exception);
}

It's important to understand that not all exceptions can be caught using try\catch such as Corrupt State Exceptions: https://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035

In this case you can debug the issue by viewing the .dmp file generated by your application found in: {Phone}\Documents\Debug

Upvotes: 0

Marino Milak
Marino Milak

Reputation: 31

Problem was with my MediaCapture. First use mediaCapture.stopPreviewAsync(); to stop preview and than you must release the mediaCapture. Before you call fileOpener use this code:

newCapture.Dispose();

Upvotes: 1

Related Questions