MCNotifyPing and s_notify_sent

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

Locked
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

MCNotifyPing and s_notify_sent

Post by monte » Mon Apr 07, 2014 4:47 am

Hi

I'm having an issue on an OS X lcidl based external LCObjectPost seems to intermittently not send the message. I'm trying to chase down the cause but in reading through the notify code I'm wondering what the purpose of s_notify_sent is because if s_notify_event is somehow true when a message comes in then it looks like it would be ignored. I'm a little bit confused why there isn't some kind of message queue.

Cheers

Monte
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: MCNotifyPing and s_notify_sent

Post by LCMark » Mon Apr 07, 2014 10:56 am

@monte: Is this with 6.6 or 6.7?

On 6.6 (where we are still using WaitNextEvent) the s_notify_sent var is used to indicate whether an Event has been sent to the Mac event queue to break WaitNextEvent and cause handling to return to the engine. This var is reset to false when MCNotifyDispatch() is called in MCScreenDC::wait.

On 6.7 the story is similar except that a different means is used to break the current event loop (MCPlatformBreakWait(), which posts an app-defined message to the Cocoa event queue to make sure it wakes up).

In both cases there is a message queue - the MCNotify API queues all posted messages which are dispatched in MCScreenDC::wait.

So, the Mac version of LCObjectPost should be using 'RunOnMainThread' to post a callback which then invokes ObjectDispatch. i.e. When LCObjectPost is called, an MCNotify callback is pushed onto the list in 'safe' mode (meaning only execute when message dispatch is allowed - equivalent to 'wait with messages', MCScreenDC::wait(dispatch == True)) which will cause MCNotifyPing to be called which should cause the OS event loop to break so that the callback can be invoked in MCNotifyDispatch called from ::wait().

Thus there's a couple of potential problems here... Either MCNotifyPing is not causing the WaitNextEvent loop to break, or the external is attempting to LCObjectPost when the engine isn't in control of the event loop (and so it isn't being broken by MCNotifyPing).

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: MCNotifyPing and s_notify_sent

Post by monte » Wed Apr 09, 2014 1:01 am

runrevmark wrote:@monte: Is this with 6.6 or 6.7?
I was reviewing the 6.6 code. I'll test against 6.7 if it's changed. The client is stuck on 6.5 at the moment because the player doesn't size properly on retina machines.
runrevmark wrote:In both cases there is a message queue - the MCNotify API queues all posted messages which are dispatched in MCScreenDC::wait.
Ah... I see it in MCNotifyPush now...
runrevmark wrote:Either MCNotifyPing is not causing the WaitNextEvent loop to break, or the external is attempting to LCObjectPost when the engine isn't in control of the event loop (and so it isn't being broken by MCNotifyPing).
Hmm... any idea how you would debug that? The external is my mergAWS and LCObjectPost is being sent by a request delegate for progress and completion. It appears to be reliable on iOS but on OS X the messages seem to not be sent occasionally. We really need the completion messages at least to be reliable.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: MCNotifyPing and s_notify_sent

Post by monte » Wed Apr 09, 2014 4:03 am

It appears things are significantly better with 6.7
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: MCNotifyPing and s_notify_sent

Post by LCMark » Wed Apr 09, 2014 9:17 am

Hmm... any idea how you would debug that? The external is my mergAWS and LCObjectPost is being sent by a request delegate for progress and completion. It appears to be reliable on iOS but on OS X the messages seem to not be sent occasionally. We really need the completion messages at least to be reliable.
There's a couple of things you could look at...

The first would be to put a breakpoint on the LCObjectPost line and see what the call stack is when LCObjectPost is being invoked.

The other would be to put some logging where LCObjectPost is being called, in MCScreenDC::pingwait and in MCNotifyDispatch - see if the problem is a delay in the wait being broken by pingwait.

In regards to being stuck at 6.5 - you could move to 6.6, but use the 'usePixelScaling' property. This turns off retina-ness and HiDPI awareness.

The player thing is a QT problem - Apple's advice with regards QT and Retina: it doesn't work, use AVFoundation. The latter will arrive with 6.7 and Cocoa.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: MCNotifyPing and s_notify_sent

Post by LCMark » Thu Oct 23, 2014 11:43 am

@monte: It turns out this problem is the one you found recently on Yosemite - http://quality.runrev.com/show_bug.cgi?id=13721. The callback that MCRunOnMainThread expects is different from the callback MCNotifyPush expects - this meant that the second argument to the runonmainthread callback is undefined on Desktop, resulting in things working on not depending on what previously might have been executed before the callback is invoked.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: MCNotifyPing and s_notify_sent

Post by monte » Thu Oct 23, 2014 11:55 pm

Thanks for hunting it down... so odd that it seemed to work fine in 6.7 on Mavericks and not on Yosemite
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Ken3D
Posts: 16
Joined: Sun Mar 02, 2014 12:54 am

Re: MCNotifyPing and s_notify_sent

Post by Ken3D » Fri Oct 24, 2014 5:56 pm

I'm having trouble with code being called from the card script to the stack script (and visa versa) on Yosemite (I didn't seem to have this problem on Mavericks). Sometimes it works and sometimes it doesn't. It seems that it's more likely to work the first time I call it but not the second time.

Is this the same problem reported above? Is there any hope for a fix any time soon?

Locked

Return to “Engine Contributors”