×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Germany
    Posts
    2

    Question PhotoCaptureDevice - Error when NavigatingFrom and then NavigatingTo

    Hi,

    I use a PhotoCaptureDevice and take the PreviewBufferY to decode a Barcode in it. If successful I navigate to another Page. If the user hits the backButton after that the app mostly crashes... I did implement a _captureDevice.Dispose() in the OnNavigatedFrom and am initializing the PhotoCaptureDevice in the OnNavigatedTo
    What am I doing wrong? Any oidea?

    Code:
    _availableCaptureResolutions =
                    PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
                _res = GetBestResolution(_availableCaptureResolutions);
                var list = PhotoCaptureDevice.GetAvailablePreviewResolutions(CameraSensorLocation.Back);
                _resPreview = GetBestPreviewResolution(list, _res);
    
                // Initalize CaptureDevice
                try
                {
                    // Always takes Preview Resolution for better barcode regognition
                    _captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, _resPreview);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                #region retry when failed hack
                if (_captureDevice == null)
                {
                    try
                    {
                        await Task.Delay(200);
                        _captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, _res);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                    if (_captureDevice == null)
                    {
                        try
                        {
                            await Task.Delay(500);
                            _captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, _res);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
                #endregion // retry when failed
                // No Flash
                try
                {
                    Debug.Assert(_captureDevice != null, "_captureDevice != null");
                    _captureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
    
                // Scene Mode
                try
                {
                    Debug.Assert(_captureDevice != null, "_captureDevice != null");
                    _captureDevice.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Macro);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
    
                _videoBrush.SetSource(_captureDevice);
    
    StartCapturingAsync();
    
    private async void StartCapturingAsync()
            {
                try
                {
                    CameraCaptureSequence sequence = _captureDevice.CreateCaptureSequence(1);
                    var stream = new MemoryStream();
                    sequence.Frames[0].CaptureStream = stream.AsOutputStream();
    
                    await _captureDevice.PrepareCaptureSequenceAsync(sequence);
                    FocusInternallyAsync();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    925

    Re: PhotoCaptureDevice - Error when NavigatingFrom and then NavigatingTo

    Didnt tested your code yet, so let me make the first obvious question... so you have a crash stack trace or the apps just exits? I notice you are using try...catch everywhere so you should get some info there. And does that happen on the emulator or on the device as well?

  3. #3
    Nokia Developer Champion
    Join Date
    Dec 2012
    Posts
    43

    Re: PhotoCaptureDevice - Error when NavigatingFrom and then NavigatingTo

    Can you create a project/demo with the problem? is more easy to test... i am confuse

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    1

    Re: PhotoCaptureDevice - Error when NavigatingFrom and then NavigatingTo

    Same problem here. It seems that in some scenarios, like Navigate to previous page then to camera works. But navigate to next page then to previous doesn't work. I've implemented everything I could. I'm nullifying everything I need, Disposing, Closing, doing an ErrorHandling in the task, but the task still doesn't appreciate it.

    me hAz success:
    A->B->A
    [A-Previous Page] [B-Camera Page][C-Next Page]

    me is a c4t failing:
    A->B->C->B
    [Previous Page] [Camera Page][Next Page]

    Any recommendation about how to properly dispose of the camera would be appreciated.

    Thanks,
    Leon Pelletier

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    470

    Re: PhotoCaptureDevice - Error when NavigatingFrom and then NavigatingTo

    Hi.
    Are you sure you don't call a method on a disposed instance or on a null element?
    Generally with C->B navigation , B is not recreated (I.e. loaded event is not performed for example). You access to the instance created with A->B navigation.

    Without code it's difficult to help you.

Similar Threads

  1. Replies: 2
    Last Post: 2012-12-26, 08:22
  2. Fatal: IO Error:SymbainOS error = -34 : General: System error
    By dharmeshkhatri in forum Mobile Java Networking & Messaging & Security
    Replies: 9
    Last Post: 2010-04-12, 15:17
  3. Replies: 1
    Last Post: 2008-06-05, 07:44
  4. Replies: 4
    Last Post: 2007-05-31, 07:06
  5. Replies: 13
    Last Post: 2006-12-01, 01:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×