touch support seems broken since qt4-x11-4.8.1

Bug #1046820 reported by Canmor Lam
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
qt4-x11 (Ubuntu)
Medium
Unassigned

Bug Description

I found that touch examples of QT (under /usr/lib/qt4/examples/touch/) works well on Ubuntu 11.10(with qt4-x11-4.7.4) but not on Ubuntu 12.04(with qt4-x11-4.8.1). On Ubuntu 12.04, touch examples of QT such as "dials", "fingerpaint", "knobs" and "pinchzoom" seems cannot get any touch event.

Then I download the source code of qt4-x11 by 'apt-get source' and debug it. I found that there may be a mistake in file "debian/patches/kubuntu_28_xi2.1.patch". Look at the codes near line 714:

702 + QApplicationPrivate::TouchDeviceInfo tdi;
703 +
704 + for (int k = 0; k < devices[i].num_classes; ++k) {
705 + XIAnyClassInfo *xiclassinfo = devices[i].classes[k];
706 + if (xiclassinfo->type == XITouchClass) {
......
712 + } else if (xiclassinfo->type == XIValuatorClass) {
713 + XIValuatorClassInfo *v = (XIValuatorClassInfo *)xiclassinfo;
714 + tdi.numValuators++;
......
728 + if (is_touch)
729 + touchDevices[devices[i].deviceid] = tdi;

Thease codes is the initialization of `touchDevices', note that `tdi' is allocated from stack without any initialization, the initial value of `tdi.numValuators' is uncertain. Its value is always a negative number on my machine, even after couples of post increase(line 714).
Trouble comes when program reaches to function `QETWidget::translateXI2Event', Look at the codes near line 563:

562 + double *values = dev->valuators.values;
563 + for (int i = 0; i < qMin(dev->valuators.mask_len * 8, tdi.numValuators); ++i) {
......
617 + }

As I mentioned earlier, `tdi.numValuators' is always a negative number, program *never* will enter this `for' loop. As a result, application cannot get any touch properties except tracking ID. That is the trouble.
I add a initializint statement for `tdi.numValuators':

702 + QApplicationPrivate::TouchDeviceInfo tdi;
703 + tdi.numValuators = 0;

The problem is solved.

Finally, I try to figure out the different between qt4-x11-4.7.4 and qt4-x11-4.8.1. Look this commit http://bazaar.launchpad.net/~kubuntu-packagers/kubuntu-packaging/qt/revision/279 :

@@ -699,17 +682,20 @@
 + for (int i = 0; i < count; ++i) {
 + if (!devices[i].enabled)
 + continue;
++
++ bool is_touch = false;
++ QApplicationPrivate::TouchDeviceInfo tdi;
++
 + for (int k = 0; k < devices[i].num_classes; ++k) {
 + XIAnyClassInfo *xiclassinfo = devices[i].classes[k];
 + if (xiclassinfo->type == XITouchClass) {
++ is_touch = true;
 + XITouchClassInfo *t = (XITouchClassInfo *)xiclassinfo;
-+ QApplicationPrivate::TouchDeviceInfo& tdi = touchDevices[devices[i].deviceid];
 + tdi.deviceid = devices[i].deviceid;
 + tdi.directTouch = t->mode == XIDirectTouch;
 + tdi.maxTouches = t->num_touches;
-+ } else if (xiclassinfo->type == XITouchValuatorClass) {
-+ XITouchValuatorClassInfo *v = (XITouchValuatorClassInfo *)xiclassinfo;
-+ QApplicationPrivate::TouchDeviceInfo &tdi = touchDevices[devices[i].deviceid];
++ } else if (xiclassinfo->type == XIValuatorClass) {
++ XIValuatorClassInfo *v = (XIValuatorClassInfo *)xiclassinfo;
 + tdi.numValuators++;
 + if (v->label == ATOM(XAbsMTTouchMajor))
 + copy(tdi.xivTouchMajor, *v);

In the older version, `tdi' is create by `QHash::operator[]' implicitly, which is allocated from heap directly, memory in heep may be clear than stack I think. Anyway, adding a default constructor for struct TouchDeviceInfo should be a beter solution.

Changed in qt4-x11 (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Canmor Lam (canmor-lam) wrote :

After 4 years, we still got a customer complain about the touch event unavailable on QT-4.8.x today, could anyone please focus on this issue and get it fix? Or some one tough me what I can do for this?

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers