Merge lp:~smspillaz/compiz-core/compiz-core.fix_911530 into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 2899
Merged at revision: 2934
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.fix_911530
Merge into: lp:compiz-core/0.9.5
Diff against target: 95 lines (+22/-14)
1 file modified
plugins/opengl/src/paint.cpp (+22/-14)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.fix_911530
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Daniel van Vugt Needs Information
Review via email: mp+87422@code.launchpad.net

Description of the change

PrivateGLScreen::paintBackground(): If background textures are empty,
fix the vertex array pointer to use the beginning of the vertex data
rather than (data + 2). Fix data allocation so only the necessary number
of vertices is allocated. Disable the unspecified texture coordinate
array in this case, since leaving it enabled may cause the GL driver to
segfault when attempting to dereference it.

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Duplicating the data allocation in 2 places not only makes the code bigger, but makes it harder to maintain (and potentially more buggy) in future. I suggest it should look more like:

    bool bgEmpty = backgroundTextures.empty ();
    int dataLen = nBox * (bgEmpty ? 8 : 16);
    data = new GLfloat [dataLen];
    if (!data)
        return;

    d = data;
    n = nBox;

    if (bgEmpty)

This should make the entire diff much smaller.

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

FYI, the main fix for bug 911530, "fix the vertex array pointer to use the beginning of the vertex data
rather than (data + 2)" is not part of this proposal at all (see line 33). Although that bug is still present in oneiric, it was apparently fixed a long time ago already in compiz-core.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

    data = new GLfloat [dataLen];
    if (!data)
        return;

Passing a variable to array new [] I've found has resulted in std::bad_alloc exceptions, even when the length specified was completely valid. This happened to be about a year ago the last time I tried, so it could have been a compiler bug.

Doing the allocation in two places also struck me as a bit odd at first as well in the patch that was submitted.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'd rather see data being of type boost::scoped_array<char> - avoiding the need for explicit deletes.

There's no need to check the return from new against 0 as operator new[] will throw bad_alloc if the allocation fails. So this code:

    data = new GLfloat [nBox * 8];
    if (!data)
        return;
...
    delete [] data;

becomes:

    data.reset(new GLfloat [nBox * 8]);

Note, the code currently only invokes C functions (which don't throw) so the there is no exception safety issue.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

This proposal is already present upstream in git. So whether or not we accept it here really depends on what the plan is for compiz in the future. Is git still upstream or is lp:compiz-core the main repo now?

Revision history for this message
Daniel van Vugt (vanvugt) :
review: Needs Information
2899. By Sam Spilsbury

Use boost::scoped_array

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/opengl/src/paint.cpp'
2--- plugins/opengl/src/paint.cpp 2012-01-19 06:08:11 +0000
3+++ plugins/opengl/src/paint.cpp 2012-01-19 14:56:54 +0000
4@@ -33,6 +33,7 @@
5 #include <math.h>
6
7 #include <boost/foreach.hpp>
8+#include <boost/scoped_array.hpp>
9 #define foreach BOOST_FOREACH
10
11 #include <opengl/opengl.h>
12@@ -70,7 +71,9 @@
13 {
14 BoxPtr pBox = const_cast <Region> (region.handle ())->rects;
15 int n, nBox = const_cast <Region> (region.handle ())->numRects;
16- GLfloat *d, *data;
17+ GLfloat *d;
18+
19+ boost::scoped_array <GLfloat> data;
20
21 if (!nBox)
22 return;
23@@ -94,15 +97,13 @@
24 backgroundLoaded = true;
25 }
26
27- data = new GLfloat [nBox * 16];
28- if (!data)
29- return;
30-
31- d = data;
32- n = nBox;
33-
34 if (backgroundTextures.empty ())
35 {
36+ data.reset (new GLfloat [nBox * 8]);
37+
38+ d = data.get ();
39+ n = nBox;
40+
41 while (n--)
42 {
43 *d++ = pBox->x1;
44@@ -120,14 +121,23 @@
45 pBox++;
46 }
47
48- glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, data);
49+ glDisableClientState (GL_TEXTURE_COORD_ARRAY);
50+
51+ glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, &data[0]);
52
53 glColor4us (0, 0, 0, std::numeric_limits<unsigned short>::max ());
54 glDrawArrays (GL_QUADS, 0, nBox * 4);
55 glColor4usv (defaultColor);
56+
57+ glEnableClientState (GL_TEXTURE_COORD_ARRAY);
58 }
59 else
60 {
61+ data.reset (new GLfloat [nBox * 16]);
62+
63+ d = data.get ();
64+ n = nBox;
65+
66 for (unsigned int i = 0; i < backgroundTextures.size (); i++)
67 {
68 GLTexture *bg = backgroundTextures[i];
69@@ -135,7 +145,7 @@
70
71 pBox = const_cast <Region> (r.handle ())->rects;
72 nBox = const_cast <Region> (r.handle ())->numRects;
73- d = data;
74+ d = data.get ();
75 n = nBox;
76
77 while (n--)
78@@ -167,8 +177,8 @@
79 pBox++;
80 }
81
82- glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data);
83- glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data + 2);
84+ glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, &data[0]);
85+ glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, &data[2]);
86
87 if (bg->name ())
88 {
89@@ -183,8 +193,6 @@
90 }
91 }
92 }
93-
94- delete [] data;
95 }
96
97

Subscribers

People subscribed via source and target branches