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
DrawHandler<DrawingArea>::get_context() triggers an extra draw event, causing a feedback loop #129
Comments
Supposing that this is by design, and not a bug: My understanding based on the drawing.rs example is that the context returned by Is it possible to change |
Don't worry, the drawing code is experimental and known to be slow (perhaps for the reasons you found out, though). |
I'd be happy to give it a try. I haven't had time to look into it yet, but I will soon. |
The reason this is happening is the following line: Line 72 in 541e1dc
What happens is that the event handler calls get_context(), which creates a DrawContext. At the end of the event handler, the DrawContext is dropped, causing the queue_draw() call. As far as I can tell, the order things happen in when something needs to be redrawn (either after resizing a window or after explicitly calling queue_draw()) is the following:
One way of solving this would be to replace the call to queue_draw() in the DrawContext destructor with something that is more or less equivalent, except for triggering another call to Update::update(). That does not feel like a proper solution though, since it still involves drawing to the screen twice every time something needs to be updated. |
That seems to be fixed in this branch. |
Description:
Calling
DrawHandler<DrawingArea>::get_context()
seems to trigger an extra draw event. Using it in the event handler, as in the drawing.rs example, causes a feedback loop where each draw event triggers a new one.An example showing the issue is given below.
Setup:
cargo init --bin relmissue
main.rs
with the code given below.Running the example:
cargo run
Observed behavior: "Updating UpdateDrawBuffer" is printed many times per second.
Expected behavior: "Updating UpdateDrawBuffer" should be printed only when the widget needs to be repainted, for instance when the window is resized.
Tweaking the example:
DrawHandler<DrawingArea>::get_context()
.cargo run
Observed and expected behavior: "Updating UpdateDrawBuffer" is printed only when the widget needs to be repainted, for instance when the window is resized.
Example code (
main.rs
):The text was updated successfully, but these errors were encountered: