[futurebasic] Re: [FB] OS X 10.7.4 crash

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2012 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Mon, 14 May 2012 09:09:13 -0700
On May 14, 2012, at 7:31 AM, Steve wrote:
> 
> begin globals
> dim as Ptr  gSndChannel(3)
> end globals
> 
> local fn AllocateChannels
> '~'1
> dim as long   j
> dim as OSErr  err
> 
> err = _noErr
> for j = 0 to 3
> Long if ( err == _noErr )
>  err = fn SndNewChannel( @gSndChannel(j), _squareWaveSynth, 0, 0 )
> End if
> next
> if ( err ) then shutdown "Could not allocate sound channel " + str$( j ) 
> 
> end fn
> 
> fn AllocateChannels
> 
> RunApplicationEventLoop()


Yes, it crashes here too. Don’t know *exactly* why it is crashing, but here are some points worth investigating:

(1) The check for 'err' should be inside the for/next loop otherwise error conditions could be missed.

(2) gSndChannel is defined as an untyped pointer. FB does this a lot in the headers but sometimes it matters if the type is correct. In C that pointer is typedef SndChannel *                    SndChannelPtr;  which points to a struct like so( see Sound.h can be found by using Search Apple Headers.app in FB help menu ):

struct SndChannel {
  SndChannelPtr       nextChan;
  Ptr                 firstMod;               /* reserved for the Sound Manager */
  SndCallBackUPP      callBack;
  long                userInfo;
  long                wait;                   /* The following is for internal Sound Manager use only.*/
  SndCommand          cmdInProgress;
  short               flags;
  short               qLength;
  short               qHead;
  short               qTail;
  SndCommand          queue[128];
};

Maybe we need all this converted to FB. 

(3) SndNewChannel and many of its brethren were deprecated as of OS 10.5, so I’d be looking for a Cocoa replacement if it were my code.

(4) FWIW the posted code doesn’t provide a callback function ( instead passes 0 ). Not sure if this is a player but maybe giving it a valid callback ( even if it does nothing ) might help. ( i.e. (ptr)@fn SomeFN ). Don’t have any doc here in Xcode 4.3 for this toolbox call ( not even in the legacy docs, so I’m gleaning all this from looking at Sounds.h in the Framework ).


Brian S.