-
Notifications
You must be signed in to change notification settings - Fork 121
Fix for unordinary behavior of size() in setup() for skia #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing to p5py
Let me know your thoughts @tushar5526 🙂 |
This looks like a good solution. Thank for the deep dive. I will test this locally soon, but it seems calling In the second example, try adding a |
Try this example and resize. See the stroke of the circle changes because setup is called again. Also, I am seeing a weird gittery behaviour at my end , some different frame buffer is getting swapped alternatively. Not sure if it is PR specific or different. It would take a proper deep dive though. |
It's definitely not PR specific. I've noticed this behavior on the current master branch as well. |
@tushar5526 I think you are right, there was this thing missing in my solution. Calling The problem:
Potential Solution:
I dived a little deep into I tried the examples that you mention, they seem to be working perfect on my end, it would be great if you could test it out too. from p5 import *
def setup():
size(512,512)
background(220)
circle(100,100,50)
def draw():
circle(mouse_x,mouse_y,50)
run(renderer="skia") Let me know your thoughts. 🙂 |
The problem with calling I think you are very close to the solution, but instead of calling setup every time frame resizes, we need to figure out a way to copy the existing PS: Following is not needed, but in case you want to go ahead one step. PS: I don't think we have to be strict with sketch refreshing completely to blank when we resize canvas manually as this happens in p5.js as well. |
Yes, not sure if this is due to some glfw/skia updates or code bugs, but this was not the behaviour earlier and maybe this was introduced in some of the recent commits. Feel free to create an issue, I would love to help |
I got your point @tushar5526 , we will have to retain our style settings if we are calling from p5 import *
def setup():
size(512,512)
background(100)
no_stroke()
circle(100,100,50)
def draw():
circle(mouse_x,mouse_y,50)
def mouse_clicked():
background('red')
stroke(0)
run(renderer="skia") Also I would be exploring if we can implement some sort of a preprocessing on Thank you for being so helpful and patient, do let me know if I am missing out on something 🙂. |
Nice fix! |
Thanks @procub3r 😃 |
Looks like a good hack. I think you should use deep copy instead of shallow copy. Otherwise changes in setup() will still be reflected in mutable style properties. |
I implemented the required changes. Doing a |
Hey, I have tested this and this looks good to me. Can you add more verbose comments in the code explaining the logic and also mention the issue number in the callback. |
Did the required changes. |
LGTM! Thanks @devAyushDubey |
This is a partial "fix" for #419 particularly for Skia Renderer. Related to #420
What I found tracing the calls are following:
GLFW
handleswindow resize events
.size()
or manually by the user, it triggers a window resize event in theglfw event queue
, this event is inherently asynchronous, so this does not take place instantly, but when it does, a callback function is called. The callback function is assigned by self.assign_callbacks() in thestart()
of SkiaSketch.new surface
with the new dimensions by self.create_surface(size=(width, height)).Now here is the issue:
self.surface
and is subsequently displayed on the window by themain_loop()
, this is the reason why anything drawn insetup()
withsize()
is not visible because a new surface is created above, everytime is size() is called.Potential Fix:
setup()
on the new surface.This is exactly what I am doing here, I have done 2 changes:
setup_method()
again after the window is resized and new surface created, so that all the renders of the previous surface is again rendered on the new surface.setup_method()
again, posed the problem of recurrent calling ofsize()
, to not let that happen, I have added a simple check in userspace.py/size() that ensures that,size()
is not called in the re-rendering call.self.resized = False
in frame_buffer_resize_callback_handler() also facilitates manual resizing of window and works perfectly fine.Now
With draw()
Manual Resizing: