psychopy.org | Reference | Downloads | Github

Scaling problems with multiple windows using different resolutions

Hi,
i have been busy coding a fairly involved setup using psychopy 3.0.0b2 with python 2.7 in pycharm. So far it worked out fairly well overall. I encoutered a bug with text stimuli and decided to upgrade to psychopy 3.0.7 with python 3.7. the transition was mostly smooth but now i encounter some strange behavior when using multiple windows with different resolutions.
When both windows use the same resolution stimuli are displayed as inteded. Changing the resolution on one window seems to influence the second in that stimuli are not displayed at the correct location and scale. I was able to narrow the cause down to the .flip() command. If only one window is flipped, everything is fine. I suspect that it has something to do with buffering and that flipping one window overwrites some parameter in the other.
I can reproduce the described behaviour with this code:

from psychopy import visual
import time

mainres = (1920, 1080)
secRes = (200,200)

win1 = visual.Window(size=mainres,
                     screen=0,
                     units="height",
                     winType='pyglet'
                     )
win2 = visual.Window(size=secRes,
                     screen=0,
                     units="height",
                     winType='pyglet'
                     )

box1 = visual.Rect(units="height", win=win1, width=1, height=1)
box2 = visual.Rect(units="height", win=win2, width=0.5, height=0.5)

while True:
    box1.draw()
    box2.draw()
    win1.flip()
    win2.flip()
    time.sleep(1)

I hope this illustrates the problem. It was not happening in 3.0.0b2 so something must have changed in the meantime.
I would be very happy if someone could help me with this.
Happy easter

I realized my problem description was not very clear. I updated the code to better illustrate the problem.
based on the code, you yould expect a simple square to be drawn on both windows. This happens only for the first frame, on subsequent frames the scaling is thrown off, causing the square to be streched and relocated on both screens.

I was able to fix this problem by overwriting the resetEyeTransform method of the window class. This method gets called in .flip() and caused mismatching defaults to be restored.
My solution in code:

# before creatig the windows:
class Window(visual.Window):
    def resetEyeTransform(self, clearDepth=True):
        pass

# then procede to use the new Window() class
win1 = Window(size=mainres)

Are you on a Mac? This sounds similar to an issue I encountered. I developed a fairly kludgy work-around.

That seems to be the same issue from what i can tell, the behavior is very similar.
I am on two windows machines, win7 and 10. I think the Issue is independent of platform.
In the .flip() method of the .window class the line:

self.resetEyeTransform(False)  # reset transformations

seems to reset to defaults on every flip. When using multiple windows with unequal resolutions the default transformations do not fit the windows any more an the contents get distorted.
You could comment out the line above in the code to quickly test if this is also the cause of your issues.

Hello,

These changes were introduced to allow the window class to handle different projections. It should be able to handle windows with different resolutions, however there seems to be something I missed. I’ll look into it and see if I can issue a patch.

1 Like

Issued a patch here which seems to fix all the problems around having mixed window configurations.

2 Likes

Thank you for looking into it and fixing it so quickly!

Usually, I use matched displays all sharing the same attributes (i.e. size, color depth, etc.) to present multiple windows, so other cases slipped through when testing it out. :confused:

In the process of fixing this issue, I found and fixed some other problem behaviours when using multiple windows. I suspect there might be a few edge cases where things might behave weird, but I doubt most people will encounter those issues before I get to them.

1 Like