Bug 5997 - RosyWriter gets hanged after clicking Record button throwing exception "MonoTouch.Foundation.MonoTouchException"
Summary: RosyWriter gets hanged after clicking Record button throwing exception "MonoT...
Alias: None
Product: iOS
Classification: Xamarin
Component: Samples ()
Version: 5.3.x
Hardware: Macintosh All
: --- normal
Target Milestone: 7.2.1
Assignee: Sebastien Pouliot
Depends on: 12950
  Show dependency tree
Reported: 2012-07-06 06:57 UTC by Nischal
Modified: 2014-03-20 07:24 UTC (History)
9 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Nischal 2012-07-06 06:57:59 UTC
Steps to reproduce:
1. Open the Rosy Writer in MD.
2. Debug/Run the application
3. Click on 'Record' button


1. Execute the Rosy writer using command line.

Actual result: After clicking Record button, Application gets hanged and throwing exception "MonoTouch.Foundation.MonoTouchException"

Expected result: Application should not hang after clicking on Record button.

Supplement info:
iOS Device Log:

Mac All
MT 5.3.5 RC3
Mono Framework 2.10.9_11 MDK

App info:
RosyWriter/MonoTouch 5.4

Regression status:
REGRESSION: This is not happening with MD and MT 5.2.12, there is another issue(Unable to build Rosy writer)
Comment 1 PJ 2012-07-06 07:20:16 UTC
This sample is not compatible with 5.2.12 so it is not a regression for the reason stated.

Let's check this against the current alpha (5.3.4). I think the sample works there.
Comment 2 PJ 2012-07-19 15:56:10 UTC
I am still seeing this on 

MT 5.3.5 RC4 8ddf0f5ded445fbe774008ba29557bf6c4b100cd
MD (stable)
iPodTouch(iOS 5.1)
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-07-19 21:32:43 UTC
This seems to be a race condition with the sample, sometimes it works, sometimes it doesn't.

The race condition seems to be that in DidOutputSampleBuffer a sample buffer is queued for write, and it's only written if recording has been enabled. The problem is that the sample buffer isn't valid unless recording has been enabled, and we may enqueue the sample buffer before recording has been enabled, but when we reach the write code, we've enabled recording, therefore we try to write an invalid sample.

Eric, I believe you wrote this sample, can you have a look?
Comment 4 Nischal 2012-07-27 07:45:54 UTC
This is also happening on iPod iOS 6.0 with the below environment:
Mountain Lion with Xcode Version 4.5 (4G125j)
Comment 5 Nischal 2012-07-27 11:27:36 UTC
We have used MT 5.99.0 7badd059e7936092321f5ee28419b9af282d6293
Comment 6 Nischal 2012-07-31 05:22:37 UTC
This issue still exists, as when click on Record button, the application crashes after sometime.

We have tested using the following:

MD 3.1.0 MonoDevelop-dc490890a9b9cddaf91cad1aaae5acb0720f064c
MT 5.99.0 9a858c922f65ebba687b72d737abe1a61cf3b694
Device: iPod iOS 6.0

Below is the link for the iOS Device logs of the same:

Note: It is working fine on iPhone iOS 5.0.1
Comment 7 Sebastien Pouliot 2012-09-05 09:05:14 UTC
Fixed in 51a89e0f9399de9ebae839b3799383b75d4ce9e3

There was a missing condition (compared to the original Apple sample [1]). With it I can record multiple times without issue (but I did not validate the whole sample so other issues could exists).

[1] http://developer.apple.com/library/ios/#samplecode/RosyWriter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011110
Comment 8 Nischal 2012-09-10 10:21:51 UTC
We are going to reopen this bug because after clicking on Record button, the application crashed on following environment:

MD Stable
MT 5.4.1 5f7bb4304a973094368ecfe1c9fcd1478cd183ef
Mono 2.10.9
Mac SnowLeopard

iOS Device:
iPod Touch 
Version 6.0

App information:
We can not get the log for this because of Issue: https://bugzilla.xamarin.com/show_bug.cgi?id=6972
Comment 10 Jatin 2012-09-14 09:08:11 UTC
We have retested this application on following builds and we are getting same error:

MD Stable
MT 5.4.1 b2e53cfa4709d5e758e5727a8b3f78f0403ca00c
Mono 2.10.9
Mountain Lion with Xcode 4.5 GM Seed

Device info:
iPod iOS6 GM Seed

Symbolicated crash report: https://gist.github.com/3721668
iOS Device log: https://gist.github.com/3721731
MD log: https://gist.github.com/3721761

This is happening on both Debug(debug) and Run(release) mode.

This is working fine on iPhone4 Version 5.1, iPhone4S version 5.1.1
Comment 11 Sebastien Pouliot 2012-09-14 09:24:14 UTC
Works fine on iPad3 w/iOS6 GM (at least when compiled with MT 5.99.4)

PJ, got an iPod4 running iOS6 GM somewhere ? or other iOS devices types running GM ? (it could be something device specific since the logs shows an ObjC, not a .NET, exception).
Comment 12 Jatin 2012-09-17 11:36:58 UTC
This issue exists with:

Mono 2.10.9
MD Stable
Monotouch-6.0.0 ff54b0f4a9e2c829607a91114fc5df353ec5122d
Device- iPod iOS6 GM Seed
Application info: xamarin-monotouch-samples-b266ecf

However, this is working fine on iPad iOS6 GM Seed.
Comment 13 Peter Collins 2012-09-18 18:14:55 UTC
Repro'd this on both Debug and Release settings:

Environment Details:
OSX 10.8
Mono 2.10.9
MD Stable
MT 6.0.0 -  8210eb47ef738ca8c11125c754df3efb85d16a7c
Xcode 4.5 GM Seed

iPhone 4s iOS6 GM Seed - consistent crash
iPod touch iOS6 GM Seed - consistent crash
iPad 2 iOS6 GM Seed - crashed on first repro attempt, did not crash on additional repro attempts after.

MD Application Output: 

Please update me if I can provide more information .
Comment 14 Saurabh 2012-11-07 10:05:16 UTC
We have checked this issue with following environment and we are getting same issue

All Mac
MD Stable
MT 6.0.7 a514a0cde3559d852e619500cac9b91980ef9f41
Mono 2.10.9_11

Device info:
Version 6.0

iOS device log:
Comment 15 PJ 2013-01-14 09:18:16 UTC
Several comments confirm the issue, setting to CONFIRMED.
Comment 18 Rolf Bjarne Kvinge [MSFT] 2013-06-28 16:40:31 UTC
Gouri, the crash in comment #17 does not look related to the rest of this bug report, can you please file a new bug report about it?
Comment 22 Akhilesh kumar 2013-07-09 10:05:04 UTC
Today I have checked this issue with following builds:

All mac
X.S 4.0.9(build 15)
Mono 3.1.1

Montouch Sample 3.0/RosyWriter

And we observed that on debug mode application gets hang after clicking on 'Record' button.This is the log for the same: https://gist.github.com/atin360/6d8ff060697f0208bd26 While on Release mode application get crashed as soon as it deployed to device. This is the log for the same: https://gist.github.com/atin360/b18b374d9d7e775167eb

Device info:
iPod Touch version 6.0
iPhone 4 version 6.1.3

Hence reopening this issue
Comment 23 PJ 2013-11-19 16:44:57 UTC
This bug was targeted for a past milestone, moving to the next non-hotfix active milestone.
Comment 24 Oleg Demchenko 2014-01-24 12:53:45 UTC
*** Bug 12950 has been marked as a duplicate of this bug. ***
Comment 26 Sebastien Pouliot 2014-01-28 20:19:56 UTC
I was able to reproduce this only twice: one time per device (and it turned out to be different than #17330).

My guess is that the issue only happens the first time the application is executed (which is why it's so difficult to reproduce). I did not try but it's possible that deleting the app (from the device) is enough (not sure since I used two recent devices which might never had rosy installed).
Comment 27 Sebastien Pouliot 2014-01-29 15:57:11 UTC
It's possible to duplicate the issue again by deleting the app.

The native exception occurs because the CMTime is not valid, i.e.

	var ts = sampleBuffer.OutputPresentationTimeStamp;
	Console.WriteLine (ts);



It's kind of weird that such condition only occurs for a freshly installed app...
Comment 28 Sebastien Pouliot 2014-01-30 14:31:27 UTC
In such cases

Console.WriteLine ("sampleBuffer {0}", sampleBuffer.Handle);


sampleBuffer 0

But it does not only happen on a fresh install (it just easier to replicate for me). There's likely a race condition - adding a few C.WL can hide the issue (almost) completely (and the sample itself has some) and removing them makes it more likely to crash.
Comment 29 Sebastien Pouliot 2014-01-30 15:56:20 UTC
There is a race when starting recording. The first `sampleBuffer` (given to `WriteSampleBuffer`) might not have been kept around (in `CompleteBufferUse`) and already be disposed (by the processing/de-green'ing done on the main thread).

The easy fix is not to optimize that case - i.e. since we always dispatch to `movieWritingQueue` then always keep the `sampleBuffer` referenced.

Part of the "clean install" reproducibility is likely because we delete any existing video file (which does not exists when first installed) and that takes just an extra bit of time (but generally enough to hide the issue).

I'm cleaning the sample (there were other issues / difference with Apple's original), removing C.WL and testing again...
Comment 30 Sebastien Pouliot 2014-01-30 16:16:49 UTC
Sample fixed/updated in master / bc75322ed9c39af41df9db509e02ae6151436faa

Note: it will require monotouch/master 1dae27c5f56c1831a6ea2782289741a7bd8a7f79 or more recent (API fix)

QA: since it's a race please test it on several devices (slower/faster) and make sure it's deleted from the device (in case it's already there).
Comment 31 Saurabh 2014-03-20 07:24:57 UTC
I have checked this issue with latest builds and with following sample repo:


Device info:
iPod Touch iOS 6.1.5 = Working Fine
iPad 3 iOS 6.1.2 = Working Fine
iPhone 4S iOS 7.0.4 = Working Fine

Now, application worked fine on both DEBUG and RELEASE mode. Application does not crash or hang on clicking Record and Stop button.

Environment info:

=== Xamarin Studio ===

Version 4.2.4 (build 32)
Installation UUID: b1fc3b76-cf00-405e-a0a1-3839ac11fe6d
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1 (5051.4)
Build 5B90f

=== Xamarin.Mac ===


=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 7342842
Build date: 2014-03-18 18:20:49-0400

=== Build Information ===

Release ID: 402040032
Git revision: a160c35dac9ab9fd32eeadaa171216316d5a5133
Build date: 2014-03-12 13:55:08-04
Xamarin addins: a779416ceabd54981ce812771a4061c942e8b872

=== Operating System ===

Mac OS X 10.9.3
Darwin Apples-iMac.local 13.2.0 Darwin Kernel Version 13.2.0
    Tue Mar 11 22:16:58 PDT 2014
    root:xnu-2422.100.4~2/RELEASE_X86_64 x86_64

Hence, closing this issue.