Mir

Merge lp:~alan-griffiths/mir/fix-1695221 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 4186
Proposed branch: lp:~alan-griffiths/mir/fix-1695221
Merge into: lp:mir
Diff against target: 103 lines (+52/-6)
2 files modified
examples/CMakeLists.txt (+4/-0)
examples/eglsquare.cpp (+48/-6)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1695221
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+325066@code.launchpad.net

Commit message

Correct eglsquare example: Don't paint from the window event handler. (LP: #1695221)

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:4185
https://mir-jenkins.ubuntu.com/job/mir-ci/3438/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/4682/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4815
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/4805
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/4805
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4805
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4718/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4718/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4718/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4718/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4718/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4718/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4718/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4718
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4718/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3438/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Hmm. Looks like a clang issue on artful and zesty...

https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4718/console

09:57:51 /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/atomic:236: error: undefined reference to '__atomic_load_8'
09:57:51 /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/atomic:225: error: undefined reference to '__atomic_store_8'
09:57:51 clang: error: linker command failed with exit code 1 (use -v to see invocation)
09:57:51 examples/CMakeFiles/mir_demo_client_eglsquare.dir/build.make:114: recipe for target 'bin/mir_demo_client_eglsquare.bin' failed

https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4718/console

09:55:32 make[3]: Leaving directory '/<<BUILDDIR>>/mir-0.27.0+artful4805bzr4185/obj-x86_64-linux-gnu'
09:55:32 /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/atomic:236: error: undefined reference to '__atomic_load_8'
09:55:32 /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/atomic:225: error: undefined reference to '__atomic_store_8'

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4186
https://mir-jenkins.ubuntu.com/job/mir-ci/3439/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4683
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4816
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/4806
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/4806
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4806
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4719/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4719
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4719/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3439/rebuild

review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Without testing this, the fix sounds reasonable.

Using GL in a Mir callback is expected to fail. Even if you remember context.make_current() and even if it works, I recall you could still hit deadlocks making Mir/GL calls from in that event callback thread.

P.S. mir_demo_client_target is intended to replace and supersede mir_demo_client_eglsquare. See also bug 1433925 and bug 1651695, which we probably don't care to fix. Those bugs don't exist in mir_demo_client_target. As such I wouldn't spend too much time trying to fix eglsquare - it's just too broken and not necessary.

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

> Without testing this, the fix sounds reasonable.
>
> Using GL in a Mir callback is expected to fail. Even if you remember
> context.make_current() and even if it works, I recall you could still hit
> deadlocks making Mir/GL calls from in that event callback thread.

That's exactly what was happening here.

> P.S. mir_demo_client_target is intended to replace and supersede
> mir_demo_client_eglsquare. See also bug 1433925 and bug 1651695, which we
> probably don't care to fix. Those bugs don't exist in mir_demo_client_target.
> As such I wouldn't spend too much time trying to fix eglsquare - it's just too
> broken and not necessary.

I spent the time because I wanted to understand the problem. Fixing was a quick confirmation of the diagnosis.

(Happy to see eglsquare deleted.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt 2017-05-26 08:33:17 +0000
+++ examples/CMakeLists.txt 2017-06-05 11:06:43 +0000
@@ -153,6 +153,10 @@
153mir_add_wrapped_executable(mir_demo_client_eglsquare eglsquare.cpp)153mir_add_wrapped_executable(mir_demo_client_eglsquare eglsquare.cpp)
154target_link_libraries(mir_demo_client_eglsquare eglapp)154target_link_libraries(mir_demo_client_eglsquare eglapp)
155155
156if ("${CMAKE_CXX_COMPILER}" MATCHES "clang")
157 target_link_libraries(mir_demo_client_eglsquare atomic)
158endif()
159
156mir_add_wrapped_executable(mir_demo_client_flicker160mir_add_wrapped_executable(mir_demo_client_flicker
157 flicker.c161 flicker.c
158)162)
159163
=== modified file 'examples/eglsquare.cpp'
--- examples/eglsquare.cpp 2017-05-23 10:51:47 +0000
+++ examples/eglsquare.cpp 2017-06-05 11:06:43 +0000
@@ -26,6 +26,8 @@
26#include <cstring>26#include <cstring>
27#include <unistd.h>27#include <unistd.h>
28#include <signal.h>28#include <signal.h>
29#include <condition_variable>
30#include <atomic>
2931
30#include "client_helpers.h"32#include "client_helpers.h"
3133
@@ -107,11 +109,24 @@
107 dimensions(active_output_dimensions(connection)),109 dimensions(active_output_dimensions(connection)),
108 context{connection, swap_interval, dimensions.width, dimensions.height},110 context{connection, swap_interval, dimensions.width, dimensions.height},
109 window{connection, dimensions.width, dimensions.height, context},111 window{connection, dimensions.width, dimensions.height, context},
110 program{context, dimensions.width, dimensions.height}112 program{context, dimensions.width, dimensions.height},
113 pos{Pos{0,0}},
114 worker{[this] { do_work(); }}
111 {115 {
112 mir_window_set_event_handler(window, &on_event, this);116 mir_window_set_event_handler(window, &on_event, this);
113 }117 }
114118
119 ~SquareRenderingSurface()
120 {
121 {
122 std::lock_guard<decltype(mutex)> lock{mutex};
123 running = false;
124 cv.notify_one();
125 }
126
127 if (worker.joinable()) worker.join();
128 }
129
115 void on_event(MirEvent const* ev)130 void on_event(MirEvent const* ev)
116 {131 {
117 if (mir_event_get_type(ev) != mir_event_type_input)132 if (mir_event_get_type(ev) != mir_event_type_input)
@@ -135,11 +150,9 @@
135 {150 {
136 return;151 return;
137 }152 }
138 context.make_current();153
139 program.draw(154 pos = Pos{x, y};
140 x/static_cast<float>(dimensions.width)*2.0 - 1.0,155 cv.notify_one();
141 y/static_cast<float>(dimensions.height)*-2.0 + 1.0);
142 context.swapbuffers();
143 }156 }
144157
145 SquareRenderingSurface(SquareRenderingSurface const&) = delete;158 SquareRenderingSurface(SquareRenderingSurface const&) = delete;
@@ -184,6 +197,35 @@
184 auto surface = reinterpret_cast<SquareRenderingSurface*>(context);197 auto surface = reinterpret_cast<SquareRenderingSurface*>(context);
185 if (surface) surface->on_event(event);198 if (surface) surface->on_event(event);
186 }199 }
200
201private:
202 void do_work()
203 {
204 std::unique_lock<decltype(mutex)> lock(mutex);
205
206 while (true)
207 {
208 cv.wait(lock);
209
210 if (!running) return;
211
212 Pos pos = this->pos;
213
214 context.make_current();
215 program.draw(
216 pos.x/static_cast<float>(dimensions.width)*2.0 - 1.0,
217 pos.y/static_cast<float>(dimensions.height)*-2.0 + 1.0);
218 context.swapbuffers();
219 }
220 }
221
222 struct Pos { float x; float y; };
223 std::atomic<Pos> pos;
224
225 std::thread worker;
226 std::condition_variable cv;
227 std::mutex mutex;
228 bool running{true};
187};229};
188}230}
189231

Subscribers

People subscribed via source and target branches