[futurebasic] Re: [FB] locking resource handles

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

From: AlStaff@...
Date: Sat, 1 May 1999 02:41:49 EDT
>I've got a routine that loads up a sound resource and puts it into a global
>handle for future use (yes, it has to be global).
>In synopsis (leaving out DIMs and CLEARs and whatnot):
>LOCAL FN loadNamedSound(soundname$)
>  tmphndl& = FN GETNAMEDRESOURCE(_"snd ",soundname$)
>  LONG IF tmphndl&
>    err = FN HLOCK(tmphndl&)
>END FN = tmphndl&
>... which is called from various FN's using
>gameSound& = FN loadNamedSound(soundname$)
>Now, I know _something_ isn't right, because now and then the code will lose
>its grip on the sound I want, and instead play a _different_ sound that was
>loaded subsequently into a _different_ handle. (No, they're not adjacent in
>the globals list.) Am I simply locking the wrong thing? Or does the, uh,
>lockedness of the original tmphndl& get transferred to the global gameSound&?
>Would it help to put in a line like
>   IF err THEN tmphndl& = 0
>before bouncing that back to the originating FN?
>What more should I be doing to make things stay put?

1. Are you unlocking it before loading a new sound?

2. You're locking a handle and then ending the FN. You should lock it after
gameSound& = FN loadNamedSound(soundname$)
unless gameSound& can be used as in #3 below.

3. If gameSound& is global and you use that same handle for all your sounds, 
then you don't need a tmphndl& in the FN at all, but you still need to do #1.

LOCAL FN loadNamedSound(soundname$)
  gameSound& = FN GETNAMEDRESOURCE(_"snd ",soundname$)
  LONG IF gameSound&
    err = FN HLOCK(gameSound&)

... which is called from various FN's using
FN loadNamedSound(soundname$)

Al Staffieri Jr.