Calling updatePixels() from a separate thread doesn't update the main window

Exactly what the title says, when I run updatePixels() from a function thats running in a thread, it doesn’t update the pixels, but calling updatePixels() from the function which I ran the thread from updates it. Example:

def func1():
    thread("func2()")
    time.sleep(2)
    updatePixels()

def func2():
    loadPixels()
    # do stuff with pixels
    ...
    updatePixels()

Where func2 takes more than 2 seconds to run, and when the program runs, it displays the loading partway through.

How can I get around this?

Sketch’s main canvas can’t be mutated outside its “Animation Thread”! :thread:

You can have a separate PGraphics for your thread and then render it on the “Animation Thread”: :bulb:
Processing.org/reference/PGraphics.html

2 Likes

Ah, thanks for that, I’ll go check it out

1 Like