[r169] OnReady inconsistant in facebook plugin

Bugs will be moved here once resolved.

Post » Fri May 16, 2014 8:19 am

Problem Description
The OnReady trigger will never be... triggered... if the facebook API is ready before the first call to the on start of layout.
I believe it's because, in the runtime Runtime.prototype.trigger function, you're preventing any trigger to fire if the sheet isn't active yet

Attach a Capx
Since the facebook plugin depends on a facebook id and the example is very small, I'll just post an image
Image

Description of Capx
Either trigger both console log action, or only the OnReady if the facebook API takes time to load

Steps to Reproduce Bug
  • press F5 or Ctrl+F5
  • look at the console output

Observed Result
Kind of race condition.

Expected Result
Either:
The facebook plugin call the window.fbAsyncInit before the start of layout
which should result in the OnReady being triggered, or put on hold to be triggered just after the start of layout
-> this is the problem

Or:
The facebook plugin call the window.fbAsyncInit after the start of layout
In this case, the onReady not being true, the part in the on start of layout will not execute
The OnReady is triggered
-> this is already working as expected

Of course, a simple thing to do for now would be
Code: Select all
Facebook: isReady
System: trigger once
     -> do things


Construct 2 Version ID
r169
Last edited by Yann on Sun Sep 14, 2014 3:32 pm, edited 1 time in total.
B
68
S
22
G
14
Posts: 1,485
Reputation: 16,561

Post » Tue May 20, 2014 12:29 pm

I can't reproduce any problem - I tried refreshing several times and it always triggered 'On ready' (and was never true with 'Is ready' on Start of Layout). There shouldn't be a race condition either because it only initialises the Facebook API in the object's instance onCreate - so the layout is already running and it is already allowed to trigger. So even if it initialises instantly it should still trigger correctly.

I'm not quite clear from your report: is the problem that 'On ready' does not trigger, or it triggers late? If it triggers at all, it's working correctly.
Scirra Founder
B
399
S
236
G
89
Posts: 24,530
Reputation: 195,402

Post » Wed May 21, 2014 7:02 am

Sorry if it wasn't clear, in the test I ran, sometimes, On ready wasn't triggered and Is Ready returned true on start of layout. I'll try to investigate. And if I can reproduce it I'll get back to you with more detail on my settings and a capx.

I'm a bit new to the facebook app creation, maybe I did something wrong setting some parameters in the facebook dev stuff.
B
68
S
22
G
14
Posts: 1,485
Reputation: 16,561

Post » Mon May 26, 2014 7:52 pm

I have seen this as well. The FB load is done very fast and the trigger comes before the layout is running. As a workaround I set up a tick to wait for the layout to start.
Code: Select all
window.fbAsyncInit = function() {
....
// Delay OnReady event so layout is loaded before trying to do events
fbRuntime.tickMe(fbInst);
};

instanceProto.tick = function () {
   // Just do this once after load
   if (fbRuntime.running_layout) {
      fbRuntime.untickMe(fbInst);
      fbReady = true;
      fbRuntime.trigger(cr.plugins_.FacebookFE.prototype.cnds.OnReady, fbInst);
   }      
};

B
18
S
7
Posts: 88
Reputation: 1,424

Post » Tue May 27, 2014 5:37 am

Yeah I do confirm, I remade the test with the exact same two events discribed above.

To be more precise, I exported the project and hosted it as a canvas app embedded in a page.
When I load the game the first time, I get Onready, but If I just F5, the OnReady isn't triggered (Ctrl+F5 sometimes triggers the OnReady)
I believe the js being in the cache, it's loaded so fast that the call to fbAsyncInit is done before the call to the system OnLayoutStart.
And I do believe that each OnCreate of each instances of object type are called before the OnLayoutStart so everything is initialized at this point, including the facebook API js added to the page. So the racing condition is quite possible.

@Arne 's solution seems ok to me

( @Ashley maybe, if you end up modifying the plugin, you could also expose a bit more data in expressions, like the fbAppID :D... For now I have to hard code the link the the apps' page (In which I have a like to unlock) for my share button, If I can access the ID directly in runtime I can generate it using events )
B
68
S
22
G
14
Posts: 1,485
Reputation: 16,561

Post » Mon Jun 02, 2014 3:35 pm

Ah, I forgot Facebook is a singleglobal and calls onCreate before a layout is ready. So it's true if it's ready very quickly it could try to fire 'On ready' when there is no layout so the trigger is lost. I've fixed it for the next build so it will trigger on the first tick if it's ready and hasn't triggered already. Hopefully that will fix it.
Scirra Founder
B
399
S
236
G
89
Posts: 24,530
Reputation: 195,402


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 3 guests