I've discovered a bug in the behavior of
setImage; I've uploaded the script
set_image_bug_demo to demonstrate (note: you'll need to create the folder
set_image_bug_demo in the images folder in order for the demo to work.)
Bug applies to Sexscripts 1.22 (November 7, 2016) and 1.23 (May 25, 2017) and possibly earlier releases
Description of bug:When
setImage is used to display a particular image file, then the script overwrites that image file on disk with new data, when a subsequent call is made to
setImage, the original image file is sometimes displayed rather than the new image. Other times, the new image is displayed, but contorted to the original image's dimensions. Behavior persists across script resets as long as the same instance of Sexscripts is running.
Workaround: A timestamp can be included in the filename to make it different. Unfortunately, this clutters up the folder
The demo code:
Code:
def FOLDER_NAME = "set_image_bug_demo/"
show("")
setImage(null)
showButton("Demonstrate Bug in setImage")
def filePath = getFile("Select a JPEG picture of a toy")
new File("images/" + FOLDER_NAME + "toy.jpg").delete()
new File("images/" + FOLDER_NAME + "toy.jpg") << new File(filePath).getBytes()
setImage(FOLDER_NAME + "toy.jpg")
showButton("original picture is showing")
filePath = getFile("Select a different JPEG picture of a toy")
new File("images/" + FOLDER_NAME + "toy.jpg").delete() // Note that we are deleting the original image
new File("images/" + FOLDER_NAME + "toy.jpg") << new File(filePath).getBytes() // The new image is saved to disk
setImage(FOLDER_NAME + "toy.jpg") // This *should* show the new image, rendered from disk, but may not
showButton("new picture should be showing, but may not be, or may be distorted")
filePath = getFile("Select a third JPEG picture of a toy")
def timestamp = getTime() // Include timestamp in the filename to avoid the bug
new File("images/" + FOLDER_NAME + "toy" + timestamp + ".jpg") << new File(filePath).getBytes()
setImage(FOLDER_NAME + "toy" + timestamp + ".jpg")
showButton("third picture is showing using workaround")