Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70078

Stale Cache when new clients join



    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 5.11.1
    • WebChannel
    • None


      I'm trying to make a video game using WebChannel. My problem is that I'm getting a stale state when new clients join. Because WebChannel only gives updates whenever properties get emitted, the clients are presented with incorrect world state always and forever.


      So looking at QMetaObjectPublisher, in the `initializeClient` method, for every new client that joins the code iterates through all the registered objects and calls the method `classInfoForObject`. Which is perfect and prevents the stale state issue right?


      Well if you take a look at the `classInfoForObject` method, you can skip everything except for the thing we're interested in, where does the state get read? And that's in the line of code where we go:

      `propertyInfo.append(wrapResult(prop.read(object), transport));`


      The `read` method is the important bit, because we're actually reading what the property is. But what's the `wrapResult` method doing?

      If you look at the `wrapResult` method, you can skip down to the bit of code where we assume we've already wrapped the object once (`else if (wrappedObjects.contains(id))`), you'll find where I assume I'm getting the stale cache from

      `classInfo = wrappedObjects.value(id).classinfo;`



      If you change that line of code to `classInfo = classInfoForObject(object, transport);`, then everything works as expected. There's probably a more elegant way to do this.

      Recursion, networking, and state. Dangerous combo.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            milianw Milian Wolff
            benhoff Ben Hoff
            0 Vote for this issue
            3 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes