Error using numpy array with ImageStim: numpy arrays used as textures should be in the range -1(black):1(white)

I am trying to create a stimulus using a numpy array as the image argument given to the ImageStim class constructor. The array is 2 dimensional with values ranging from -1 to +1, and the dtype is numpy.float64. The stimulus renders as expected; however, when I close the window, I receive this exact error message :

“<timestamp> ERROR numpy arrays used as textures should be in the range -1(black):1(white)”

I have tried duplicating the array along a 3rd dimension giving it all three channels, but the error message persists. I also tried making the array contiguous as suggested in this post, but that did not work either.

Here is a minimal example of the code I am using, and I tried to upload a npy file (file extension not permitted), then a csv file (file to large), so I’m kind of at a loss for how to attach an example image to this post.

# make a dummy array within the range of (-1, 1)
image = np.random.uniform(-1, 1, [480, 720]).astype(np.float64)

# create the window
from psychopy import visual
window = visual.Window(size=[720,480])

# create the stimulus
stim = visual.ImageStim(window, image=image)

# draw and render
stim.draw()
window.flip()

# close the window
window.close() # error is raised when the window is closed

I am using PsychoPy version 2020.2.1

Running the code you shared in my Python console doesn’t throw any errors, could you save the 2d array as a csv? You could also do the following to check that it is in the range specified by the error message:

(image >= -1).all() and (image <= 1).all()

You’re a few bug fixes behind too so it may be something resulting from a bug we’ve fixed in the last few versions, it’s worth updating to 2020.2.4 just in case