# Multiwindow update/draw call issue

**URL:** <https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566>\
**Category:** Using Cinder\
**Created:** [February 20, 2017, 11:54am UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566 "2017-02-20T11:54:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [February 20, 2017, 11:54am UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/1 "2017-02-20T11:54:43Z")

</div>

I have encountered a strange issue in a multiwindow setting on OSX 10.12 that I haven’t seen before.  
If I call some gl commands from `update`, like drawing to an Fbo, it seems to be interfering with the multiwindow `draw` methods.

Here’s a small sample that opens two windows and draws a window size rectangle in both of them that should look like this:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/0badedef32e9b5ddd165550e6020590a4435789d.png)

But sometimes (about 2 out of 5 times) it looks like this when switching between the windows.

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/cebf43a24412c6299b2c59625ac40a4348a43062.png)

As far as I know `update` is called before all the window `draw`'s, so I don’t really understand what is happening. Am I doing something wrong? Any help would be appreciated.

```auto
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"

using namespace ci;
using namespace ci::app;

class MultiWindowApp : public App
{
 public:
	void setup() override;
	void update() override;
	void drawWindow1();
	void drawWindow2();

 private:
	app::WindowRef mWindow1;
	app::WindowRef mWindow2;
};

void MultiWindowApp::setup()
{
	mWindow1 = app::getWindow();
	mWindow1->setTitle( "Window1" );
	mWindow1->getSignalDraw().connect( std::bind( &MultiWindowApp::drawWindow1, this ) );

	mWindow2 = createWindow( Window::Format().size( 800, 600 ) );
	mWindow2->setTitle( "Window2" );
	mWindow2->getSignalDraw().connect( std::bind( &MultiWindowApp::drawWindow2, this ) );
}

void MultiWindowApp::update()
{
	// this triggers the weird behaviour
	gl::ScopedViewport viewport( getWindowSize() / 2 );
}

void MultiWindowApp::drawWindow1()
{
	gl::ScopedViewport viewport( getWindowSize() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( getWindowSize() );

	gl::clear();
	gl::ScopedColor color( Color( 1, 0, 0 ) );
	gl::drawSolidRect( getWindowBounds() );
}

void MultiWindowApp::drawWindow2()
{
	gl::ScopedViewport viewport( getWindowSize() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( getWindowSize() );

	gl::clear();
	gl::ScopedColor color( Color( 1, 0, 1 ) );
	gl::drawSolidRect( getWindowBounds() );
}

CINDER_APP( MultiWindowApp, RendererGl )

```

---

<div class="post-metadata">

**Author:** ![dashandslash](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/dashandslash/32/112_2.png) [@dashandslash](https://discourse.libcinder.org/u/dashandslash)\
**Post date:** [February 20, 2017, 12:17pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/2 "2017-02-20T12:17:08Z")

</div>

I am wondering if you need to specify which WindowSize you want to apply in the viewport for that window.

You could try getWindowIndex(…)-\>getSize() or something like that…

L

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [February 20, 2017, 1:23pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/3 "2017-02-20T13:23:15Z")

</div>

Thanks. I think it should work like this, but tried using `mWindow1->getSize()`, `mWindow1->getBounds()`, etc, but it didn’t help.

---

<div class="post-metadata">

**Author:** ![robinjungers](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/robinjungers/32/391_2.png) [@robinjungers](https://discourse.libcinder.org/u/robinjungers)\
**Post date:** [March 16, 2018, 4:45pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/4 "2018-03-16T16:45:25Z")

</div>

Hey @gabor_papp, did you come to any conclusion with this issue ?  
I’m experiencing the exact same thing ; my main window uses a Fbo, so I have to call some gl commands before the draw (at least to allocate / re-allocate it on resize).  
I’m really confused by how random it is. I’m guessing the problem occurs during the initialization, since it only appears from time to time (like you said, about 2 out of 5 times).

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [March 16, 2018, 5:20pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/5 "2018-03-16T17:20:32Z")

</div>

I moved the fbo drawing from update to one of the draw methods as a workaround. Could not find any better solutions.

---

<div class="post-metadata">

**Author:** ![robinjungers](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/robinjungers/32/391_2.png) [@robinjungers](https://discourse.libcinder.org/u/robinjungers)\
**Post date:** [March 16, 2018, 5:38pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/6 "2018-03-16T17:38:19Z")

</div>

I see. I’ll do the same for now but it looks like a behavior that should be discussed somewhere.

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [March 16, 2018, 8:29pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/7 "2018-03-16T20:29:40Z")

</div>

`YourApp::update()` is only called once per frame, and `YourApp::draw()` is called once _for each window_ per frame.

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [March 16, 2018, 8:51pm UTC](https://discourse.libcinder.org/t/multiwindow-update-draw-call-issue/566/8 "2018-03-16T20:51:15Z")

</div>

I meant that I put the fbo render in one of the window’s `draw` like `drawWindow1()` in the example. Ideally it would be better in `update()` as it needs to be called once each frame, but it didn’t work for the reason discussed above.
