TouchCanvas bug = source of Pencil pressure bug in 3rd party apps

Hopefully this is the right location. I couldn't find a section specifically about the Pencil, or touch input in general.


Basically all of the 3rd party apps are seeing a pressure error where the start of a line has a constant placeholder pressure value (moderately large value, 0.33). The corrections fail to apply correct pressure data.


Apparently this is the result of a bug in the TouchCanvas example app, which is more or less the documentation for the new Pencil-focused touch improvements. A misplaced NOT operator is causing corrections to be applied to points that don't need them, and corrections that are needed to be skipped.


You'll find this bit of code in Line.swift in the LinePoint::updateWithTouch function

        for expectedProperty in touchProperties {
            guard !estimatedPropertiesExpectingUpdates.contains(expectedProperty) else { continue }


What this is trying to do is bail on any updated touch event data if this point wasn't originally flagged as "update pending" for that parameter. Only points that were created with known temporary data are scheduled to be updated, and updated data for points that aren't scheduled is unreliable and shouldn't be used.


Due to the NOT operator it's working backwards. Updates are discarded when they're needed, and applied when they're not (which may apply garbage data). Should be:

        for expectedProperty in touchProperties {
            guard estimatedPropertiesExpectingUpdates.contains(expectedProperty) else { continue }


The bug in this demo app has clearly been propagated to 3rd party apps with Pencil support. At least Procreate, OneNote and Notability are having an issue with high pressure blobs appearing at the start of their strokes, which was also an issue in TouchCanvas which is fixed by this change. Because the test was backwards, force corrections would be skipped when they were scheduled (those placeholder value points).


This fixes another bug with the app: In debug mode all Pencil input was staying as orange "waiting for update" points indefinitely, again because the bit mask test was working backwards (will never clear the mask if you don't ever perform the correction). After the fix the points will turn black (normal touch data) and green (coalesced) as they should.


To make the nature of the issue more obvious I recommend chaning the magnitude definition in Line.swift to something like this:

var magnitude: CGFloat {
        return max(force * 75, 0.025)
    }


Which will give a much wider pressure range. Try drawing lines with and without the fix above and you'll see the "blob" issue, and the corrections that occur to remove those blobs after the fix.


Whew. Somoene tell all the paint and note program developers, not to mention whoever's maintaining the demo app code.

Procreate is not based on (and does not use) this sample code.

TouchCanvas bug = source of Pencil pressure bug in 3rd party apps
 
 
Q