# Program spends several seconds in eglSwapBuffers

**URL:** <https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254>\
**Category:** Uncategorized\
**Created:** [August 13, 2020, 7:16am UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254 "2020-08-13T07:16:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![desperado](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@desperado](https://forums.imgtec.com/u/desperado)\
**Post date:** [August 13, 2020, 7:16am UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254/1 "2020-08-13T07:16:23Z")

</div>

I have a problem where for some reason the program now spends multiple seconds at the second eglSwapBuffers call during program startup. Appearently it waits inside the wl\_display\_poll method inside wayland:

```auto
#0 0x0000007f8a4d0ffc in __GI___ poll (fds=fds@entry=0x7f698fde98, nfds=nfds@entry=1, timeout=timeout@entry=-1) at ../sysdeps/unix/sysv/linux/generic/poll.c:38
#1 0x0000007f8c214728 in wl_display_poll (events=events@entry=1, display=<optimized out>)
    at /home/jenkins-slave/workspace/5c078a9b05b7cdd0f6fef4d97b1d63c0/work/system/ext-wayland/src/1/workspace/wayland-1.14.0/src/wayland-client.c:1593
#2 0x0000007f8c2159ec in wl_display_dispatch_queue (display=0x22509e10, queue=0x225c3b30)
    at /home/jenkins-slave/workspace/5c078a9b05b7cdd0f6fef4d97b1d63c0/work/system/ext-wayland/src/1/workspace/wayland-1.14.0/src/wayland-client.c:1666

```

I thought I could solve the problem with eglSwapInterval(\<…\>,0), but it is already used.  
What can the problem be?

Edit: How can I Post a long log here?

---

<div class="post-metadata">

**Author:** ![desperado](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@desperado](https://forums.imgtec.com/u/desperado)\
**Post date:** [August 13, 2020, 9:26am UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254/2 "2020-08-13T09:26:59Z")

</div>

Btw, does eglSwapInterval have to be called separately for every surface x context combination?

---

<div class="post-metadata">

**Author:** ![AlejandroC](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@AlejandroC](https://forums.imgtec.com/u/AlejandroC)\
**Post date:** [August 13, 2020, 11:56am UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254/3 "2020-08-13T11:56:05Z")

</div>

Hi desperado,

If you’re working with several surfaces, make sure you’re calling makeCurrent prior to the eglSwapBuffers call and that you do this for all surfaces. Also and since I don’t know what platform are you working with, make sure the surfaces you’re working with are double buffered since that’s the purpose of eglSwapBuffers.

eglSwapInterval applies to the draw surface bound to the context that is current. If you’re using more than one surface, you will need to call eglSwapInterval for each surface making sure you previously make current the surface.

You can simply post the log as part of the message.

Please let me know if you continue experiencing any issues,

Regards,  
Alejandro

---

<div class="post-metadata">

**Author:** ![desperado](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@desperado](https://forums.imgtec.com/u/desperado)\
**Post date:** [August 13, 2020, 12:21pm UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254/4 "2020-08-13T12:21:39Z")

</div>

Thanks for the answer. But I only have to call glSwapInterval once for every surface regardless of future eglMakeCurrent calls, right?

---

<div class="post-metadata">

**Author:** ![AlejandroC](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@AlejandroC](https://forums.imgtec.com/u/AlejandroC)\
**Post date:** [August 14, 2020, 3:26pm UTC](https://forums.imgtec.com/t/program-spends-several-seconds-in-eglswapbuffers/3254/5 "2020-08-14T15:26:39Z")

</div>

Yes, you should proceed that way.

Also, and as a test in case it’s not too time consuming for you, you can try avoiding any shader being compiled during your entire program exection. Just drawing an empty scene with a clear color. If at that point you do not experience this delay during the program startup, it might be related with drivers doing last-second work / optimizations.

Best regards,  
Alejandro
