| Reference | Downloads | Github

Shapestim size and _vertices_px don't match

I have a routine where you change the length of a line by moving the mouse. I have set the line size to update every repeat to:

(lineLen*2, 0)

Additionally, I use this piece of code on each frame to change the line length using the mouse and to end the trial with a key press:

# Capture key press
keyPressed = keyboard.getKeys(keyList=['v'], waitRelease=False, clear=True)

# Check if end trial
if len(keyPressed) > 0:
    rt_peripheral = keyPressed[0].rt
    continueRoutine = False

# Get pos to compare movement when est.
# line appears.
if not estimationReset:
    estimationReset = True

# Get mouse movement and update average length value
mouseMov = mouse.getRel()[0]
if mouseMov != 0:
    lineLen += mouseMov 
    # Max length correction
    if abs(lineLen) > 400:
        lineLen = 400 * getNumSign(lineLen)
    # Set new length
    line.setSize((lineLen * 2), 0)

Then I log the line.size, line._vertices_px and lineLen. The thing is that line.size and lineLen match but not line._vertices_px. The last one is sometimes (last time it was 30 times out of 300) off by 1 to 15 pixels.

Any idea on why _vertices_px is off compared to line.size?

So, digging around in the source code I saw that when you call ShapeStim.setSize() the stimuli is set to be updated when _getPolygon() is called. And then ._vertices_px is updated according to the size within _getVertices_px() is called.

So is it possible that the vertices were not updated when creating the Pixi Polygon? or something else? :upside_down_face: :upside_down_face: :upside_down_face:

1 Like

I got similar issues with updating ventrices, but then with clickable simuli that need to be drawn from .setAutoDraw(False) to .setAutoDraw(True). It seems that ._updateVertices is not always doing their job when drawing polygons. I fixed it by explicitly updating size and ventrices in the ‚ÄėEach Frame‚Äô tab once the condition is met, using stim._needVertexUpdate = True.
See also:

So I tried this ( I missread the code of the answer you posted):

stim.setSize((newLen*2), 0))
stim._needVertexUpdate = True

and the actual suggested answer:

stim.size = [(newLen*2), 0]
stim._needVertexUpdate = True

None of them worked tho. I still have around 30 out 300 trials with differences between stim.verticesPix and stim.size.

I finally solved it. Just for history sake. The problem seems way more prevalent when running the experiment in a Windows 10 Hp laptop machine (30% of trials) than a machine with Ubuntu 18.04 (10% of the trials). No idea if that’s relevant for the fix.

Anyway, update the size, then setting the _needVertexUpdate to True, and finally calling .getPolygon did the trick.

stim.size = [new_length, 0]
stim._needVertexUpdate = True