Debugger permissions?

Mac OSX specific forum
User avatar
mk-soft
Addict
Addict
Posts: 2956
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Debugger permissions?

Post by mk-soft »

I have taken a look at the code.

I noticed that cocoamessage is used in the play(dummy) thread.

In a thread, you have to create a cocoa pool yourself so that it does not conflict with the pool from the MainScope (internal PB). The internal Cocoa Pool is cleaned up when WaitWindowEvent is called. Otherwise this leads to the described error in WaitWindowEvent.

You should also NOT use KillThread, but a variable that tells the thread that it should be terminated.
KillThread only leads to memory leaks ...

Update code Play

Code: Select all

Procedure play(dummy)
  Shared AVAudioPlayer
  Shared nowPlaying
  Protected NSPool.i
  Protected currentTime.d
  
  NSPool = CocoaMessage(0, 0, "NSAutoreleasePool new")
  
  debugLog("playback",nowPlaying\path)
  AVAudioPlayer = CocoaMessage(0,CocoaMessage(0,0,"AVAudioPlayer alloc"),
                               "initWithContentsOfURL:",CocoaMessage(0,0,"NSURL fileURLWithPath:$",@nowPlaying\path),
                               "error:",#Null)
  If AVAudioPlayer
    If CocoaMessage(0,AVAudioPlayer,"play") = #YES
      PostEvent(#evPlayStart)
      While CocoaMessage(0,AVAudioPlayer,"isPlaying") Or nowPlaying\isPaused
        Delay(10)
      Wend
    EndIf
    CocoaMessage(0,AVAudioPlayer,"dealloc")
    AVAudioPlayer = 0
  EndIf
  PostEvent(#evPlayFinish)
  
  CocoaMessage(0, NSPool, "release")
  
EndProcedure
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
User avatar
deseven
Enthusiast
Enthusiast
Posts: 252
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Debugger permissions?

Post by deseven »

mk-soft wrote:In a thread, you have to create a cocoa pool yourself so that it does not conflict with the pool from the MainScope (internal PB). The internal Cocoa Pool is cleaned up when WaitWindowEvent is called. Otherwise this leads to the described error in WaitWindowEvent.
Ah, so that is what this fix was about...
mk-soft wrote:You should also NOT use KillThread, but a variable that tells the thread that it should be terminated.
KillThread only leads to memory leaks ...
Yeah, you're obviously correct, i'm just being lazy.

Thank you so much! I didn't even hope that someone will actually look into it. I'll try again with this new info.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 252
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Debugger permissions?

Post by deseven »

@mk-soft
I did a massive refactoring based on your comments and i can finally say that everything seems to be stable now. The culprit was the usage of CococaMessage() inside threads and the fix with NSPool works for that just fine.
This means a lot to me, thank you!

P.S. Also got rid of almost all KillThread() calls, although this wasn't the cause for instability.
Post Reply