Bug 37657 - crash cause of OutputAudioQueue.AllocateBuffer(size,out ptrbuf); returning invalid buffers..
Summary: crash cause of OutputAudioQueue.AllocateBuffer(size,out ptrbuf); returning in...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 2.4.0 (C6)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2016-01-13 18:05 UTC by renan jegouzo
Modified: 2016-01-14 09:10 UTC (History)
1 user (show)

Tags:
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:
Status:
RESOLVED FIXED

Description renan jegouzo 2016-01-13 18:05:46 UTC
crash with simple silent OutputAudioQueue

sample project:
http://share.aestesis.org/TestAudioQueue.zip



Xamarin Studio
Version 5.10.1 (build 6)
Installation UUID: 2a46676f-5eb8-4569-9aa7-630cd15bdfc2
Runtime:
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 7.2 (9548)
Build 7C68

Xamarin.iOS
Version: 9.4.0.0 (Business Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500

Xamarin.Mac
Version: 2.4.0.109 (Business Edition)

Build Information
Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

Operating System
Mac OS X 10.11.2
Darwin macbook.home 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 1 renan jegouzo 2016-01-13 19:06:33 UTC
if you comment the AppDelegate.cs:line 37
like this
//Marshal.Copy(data,0,pbuf,data.Length);

no crash
Comment 2 Chris Hamons 2016-01-13 20:10:12 UTC
So this is not a bug with Xamarin.Mac. You are misusing the Api in question. As you can see here:

https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/AudioQueueReference/#//apple_ref/c/func/AudioQueueAllocateBuffer

https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/AudioQueueReference/#//apple_ref/c/tdef/AudioQueueBuffer

and in these random internet examples:
http://stackoverflow.com/questions/6136064/audioqueueenqueuebuffer-failing
https://gist.github.com/hngrhorace/1360885

The AudioQueueBufferRef value is not simply a buffer you can copy into. Your code is spraying memory with the marshal call and thus crashing.

This API is rather non-trivial to learn, to say it nicely. You can look at examples here:

https://github.com/xamarin/monotouch-samples/blob/master/AQTapDemo/CCFWebRadioPlayer.cs

(which is iOS, but should apply mostly to XM)

And here's a hacky sample I released when people on the forums ran into issues:

https://forums.xamarin.com/discussion/comment/87828/#Comment_87828

Good Luck.
Comment 3 renan jegouzo 2016-01-14 07:05:17 UTC
I know this sample, I use it too.
there is no reason for the crash, in the official documentation you gave me.

the project is like this one (in objective C)

https://gist.github.com/hngrhorace/1360885
Comment 4 renan jegouzo 2016-01-14 07:27:40 UTC
OK, I fixed the crash with

for(int i=0; i<oggBufferCount; i++) {
  unsafe {
    AudioQueueBuffer* aqb; 
      var st=output.AllocateBuffer(oggBufferSize,out aqb);
      if(st!=AudioQueueStatus.Ok)
        throw new Exception(st.ToString());
      enqueue(aqb->AudioData);
  }
}

I think it' important to have a working simple OutputAudioQueue example, to get the trick.

now I have a problem with the CFRunLoop.Current.Run();
that exits immediatly
Comment 5 renan jegouzo 2016-01-14 07:29:55 UTC
oops the complete code
https://gist.github.com/renanyoy/bebe23317c197c53311b
Comment 6 renan jegouzo 2016-01-14 08:17:43 UTC
I started programming in assembly language on z80, after 68000, X86 and ARM. I can tell it's
Comment 7 renan jegouzo 2016-01-14 08:18:10 UTC
a simple API, the only problem here is Xamarin
Comment 8 renan jegouzo 2016-01-14 08:39:04 UTC
API that is really fuzzy
Comment 9 renan jegouzo 2016-01-14 08:40:28 UTC
Xamarin wrapper**
Comment 10 renan jegouzo 2016-01-14 09:10:18 UTC
ok I got it, it works
https://gist.github.com/renanyoy/bebe23317c197c53311b