PDA

View Full Version : System Sound Services




applefanDrew
May 31, 2011, 07:12 AM
Hey guys,

I could use a little help in trying to fix a bug I have within my app. I use AudioServicesPlaySystemSound to play a few different kinds of alerts within my app. Basically, I have 10 nibs (starting with a main menu) and as you progress through the game you move on to each one in succession. On the last one, you win the game, hit a button and it takes you back to the main menu. The problem occurs once I beat the game, go back to the main menu, put the app in the background, and then reopen it. When I reopen it and hit the "play" button (i.e. to start another game), it randomly plays the "Win Game" sound (maybe a 5-8 second sound) from the previous game's win menu. I can't figure out why. I have tried releasing everything I can think of, disposed of the System sound IDs, etc. The only thing that makes sense is that the previous game's "win menu" must get called upon return to the foreground but I don't know why that would happen.

Any help would be appreciated. I have stuggled with this for a week.

:apple:



chown33
May 31, 2011, 12:34 PM
Use the debugger.

Whatever function or method plays the "win game" sound, put a breakpoint on it. Play the game. Move it to background, then to foreground, click the problematic Play button. When the breakpoint triggers for the unwanted sound play, figure out where it's getting called from.

If you don't know how to use the debugger, now is a good time to learn. You will not be able to solve complicated bugs without knowing how to use the debugger. It's at least as much an essential tool as the compiler is.


Without seeing code, there's no way for anyone to debug this. We could try debugging your description using logic, but there's no way to know whether your description has been accurately transcribed into code. So your description could be bug-free but your code still has a bug in it.

applefanDrew
May 31, 2011, 12:58 PM
Thanks. I have used the debugger before...I didn't know it would work for backgrounding and foregrounding an app. The other problem is it happens intermittently. I don't know what the condition is to trigger it. I can get it to happen once or twice a day...while spending the entire day testing my app.

chown33
May 31, 2011, 01:14 PM
Then you probably need to setup some automated testing, or at least some other way you can exercise the program.


What have you tried?

Have you tried any of the Instruments tools? Maybe it will find an over-release or some other defect that doesn't cause immediate problems.

Have you tried doing Build and Analyze? It can often find logic errors, including over-release or under-retain.

And I still don't see how anyone can help find the bug without seeing code, and actually having the entire program to run. It's not like there's an obvious logic flaw in your description. Some things don't make sense, like what a "win menu" is (is it an NSMenu or NSView or what?), but I see no glaring logic flaws.

applefanDrew
May 31, 2011, 01:35 PM
I have done build and analyze. It found some memory leaks which I am working on fixing. I have not used any instruments tools. I'll check them out. as for code, I am away from my computer so it will be tonight or tomorrow before I could post some of it. Could the (as of now) unfixed memory leaks cause the problem? Have you heard of that happening before? Thanks for taking the time to reply. :)

P.s. Win menu is just a UIView with a nib.

chown33
May 31, 2011, 03:02 PM
Could the (as of now) unfixed memory leaks cause the problem?
Hard to say, without seeing code.

Have you heard of that happening before?
A leak usually just consumes memory. That might eventually lead to weird behavior.


Have you tried compiling and running your program with Garbage Collection enabled? If so, does the behavior change? If not, try it and see what happens.


P.s. Win menu is just a UIView with a nib.
UIView or NSView?

If it's UIView, then this thread is in the wrong forum. It should be in the iPhone/iPad Programming forum.

applefanDrew
May 31, 2011, 09:25 PM
So sorry. I just thought Mac programming constituted all programming for Apple on this site. I didn't even look/see the iPhone programming section. With iOS garbage collection isn't an option (as I'm sure you know). Sorry again! :(