Kivy 'drawn' items disappearing

160 views
Skip to first unread message

Dave Lawrence

unread,
Mar 8, 2019, 5:30:54 AM3/8/19
to Kivy users support
Hi,

Very occasionally our kivy-based UI glitches in a very odd way: the system remains responsive and the displays of buttons and text work but it seems that all "drawn" items disappear, i.e. items from kivy.graphics.

Here is the main control screen in it's proper state:

kivy-ok.png

and when it goes wrong it changes to:

kivy-broken.jpg


All the items rendered with the kivy.graphics objects have gone!

This is using 1.9.1-1build3 (in Ubuntu) and 1.9.1-dev (from kivypie on an RPi)

Does anyone have a clue as to what might be causing this or how to track it down? It seems to happen on touch events, but it is so rare it's been impossible so far to find any commonality and there is no error report output to stdout/stderr or the .kivy/log/

Thank you

Elliot Garbus

unread,
Mar 8, 2019, 12:18:48 PM3/8/19
to kivy-...@googlegroups.com

Here are a few ideas --- just some suggestions.

Do you have the latest graphics drivers for your machine?
If you can try your app on a different platform to rule out driver issues. 

If you believe this is happening during touch events, you could log all the touch events, it may give you an indication of what is causing the problem.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8752c0bb-31a8-4cb3-be87-a1c5ae8b6327%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Lawrence

unread,
Mar 8, 2019, 2:33:09 PM3/8/19
to Kivy users support
Hi Elliot,
Thanks for your reply.

The Same problem has been seen on an RPi running "kivypie" other on a Ubuntu/Bionic so it would seem unlikely this is a graphics driver problem. Everything else about the app continues to run; all the other display elements are present (buttons and text), just the Line, Circle, etc. items have gone.

I don't suspect a touch event specifically causing the problem, but something about user interaction triggers it (swapping displays or other). i.e. it doesn't happen spontaneously.

Elliot Garbus

unread,
Mar 8, 2019, 3:15:12 PM3/8/19
to kivy-...@googlegroups.com
Please share the code you are using to render on the canvas. 

Are these objects under a ‘canvas.after:’ in KV?  Or just a ‘canvas:’ ? 

Sent from my iPad

Dave Lawrence

unread,
Mar 10, 2019, 8:57:50 AM3/10/19
to Kivy users support
Hi,
I can't easily share the whole application, but this is a typical object used to render part of the display:

class LineWidget(GUIWidget):
   
"""A line widget. A simple sequence of points"""
   
def __init__(self, points, width, **kwargs):
       
GUIWidget.__init__(self, **kwargs)
       
self.points = points
       
with self.canvas:
           
self.line_color = theme.system.line.Color()
           
self.line = Line(width=width)
       
self.bind(size=self.update_rect, pos=self.update_rect)

   
def update_rect(self, instance, value):
       
"""Update the point positions."""
       
self.pos = instance.pos
       
if self.points:
           
self.line.points = self.get_points(self.points)

   
def set_color(self, color):
       
"""Change the color"""
       
self.line_color.rgb = color

Elliot Garbus

unread,
Mar 10, 2019, 12:38:15 PM3/10/19
to kivy-...@googlegroups.com

Here is a suggestion:

Change ‘with self.canvas:’ to ‘with self.canvas.after:’ 

 

Just a guess on my part, perhaps something is changing the rendering order, and ‘your’ canvas is ending up below another layer.

Hi,

and when it goes wrong it changes to:

 

All the items rendered with the kivy.graphics objects have gone!

 

This is using 1.9.1-1build3 (in Ubuntu) and 1.9.1-dev (from kivypie on an RPi)

 

Does anyone have a clue as to what might be causing this or how to track it down? It seems to happen on touch events, but it is so rare it's been impossible so far to find any commonality and there is no error report output to stdout/stderr or the .kivy/log/

 

Thank you

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8752c0bb-31a8-4cb3-be87-a1c5ae8b6327%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c5364b2b-8ff2-4119-ac68-76d3d86f5858%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.

Dave Lawrence

unread,
Mar 10, 2019, 1:08:26 PM3/10/19
to Kivy users support
Hi,
That's a plausible thought; (although I didn't think it was possible to change the order after widgets had be add()'d - am I wrong about that?)
Is there some other way z-order might change?
Thanks,

Elliot Garbus

unread,
Mar 10, 2019, 1:22:32 PM3/10/19
to kivy-...@googlegroups.com

although I didn't think it was possible to change the order after widgets had be add()'d

 

I’m not a Kivy developer – just a user.  This is how I understand things.  Adding a widget adds the widget to the widget tree data structure.  The canvas is simply a set of drawing instructions.  There is a property to draw in 3 layers, canvas.before, canvas, and canvas.after.    

 

I’ve done limited work with the canvas using it to create custom widgets.  I had to use these layering functions to have the custom widget render correctly.  I put the background image on canvas.before, and the dynamic elements on canvas.after.

 

It could be there is a race condition drawing the kivy native widgets on the canvas and your drawing, resulting in at some odd interval you lose, and end up below what is drawn.

 

Give it a try and let me know if it works out.

Dave Lawrence

unread,
Mar 11, 2019, 5:24:48 AM3/11/19
to Kivy users support
Hi,

This does like seem a reasonable explanation -- i.e. normal order has been disrupted and my graphics being wiped out. I have asked on StackOverflow (with a link to here) to find out if this has been seen before. Main thing I need is a guaranteed way to provoke the fault to know when it has been fixed!

I've been checking the rest of the code and the grey/blue background is drawn in a canvas.before:

        with self.canvas.before:
           
if background_color is None:
                background_color
= theme.primary.black
           
self._background_color = Color(*background_color)
           
self._background_rectangle = Rectangle(size=self.size, pos=self.pos)



(I can't remember why!) but I don't think this would explain the problem.

Elliot Garbus

unread,
Mar 11, 2019, 9:14:13 AM3/11/19
to kivy-...@googlegroups.com

Here is an idea to help with the debug.

Use the callback statement to print (or log) when the drawing is happening.

https://kivy.org/doc/stable/api-kivy.graphics.instructions.html?highlight=canvas%20callback

 

I’d suggest printing the time and the enough description to know what is being printed.  This could show if the layers were being printed in the wrong order.  

Dave Lawrence

unread,
Mar 12, 2019, 9:20:13 AM3/12/19
to Kivy users support
I added a Callback() at the end of each 'with canvas...' block which dumped stuff about the widgets and pos and size. I've yet to get any closer to the disappearing graphics, but I did find something unexpected; it seems that each 'block' is being hanled twice!? i.e. I get two Callback()'s for each one. And it's definitely the same object twice, as the id() is the same. e.g.:

        with self.canvas:
           
self.body_color = theme.system.amplifier_body.Color()
           
self.body = Triangle()
           
self.line_color = theme.system.amplifier_border.Color()
           
self.line = Line(width=border_line_width, close=True)
           
if self.app.debug_info:
               
Callback(self._debug_info)

and it's definitely on add_widget()'d once.

Elliot Garbus

unread,
Mar 12, 2019, 2:25:30 PM3/12/19
to kivy-...@googlegroups.com

Fascinating.  Can you share the output you are collecting from the callback?

 

Have you used canvas.after?

 

What did you mean by: ‘it's definitely on add_widget()'d once.’ ?

 

My mental model:
on calling add_widget(), the canvas code would be executed (scheduled to be executed).
from the app.run() loop, the canvas code would be executed if there was an event that could change the screen.

Dave Lawrence

unread,
Mar 12, 2019, 6:45:09 PM3/12/19
to Kivy users support


On Tuesday, March 12, 2019 at 6:25:30 PM UTC, Elliot Garbus wrote:

Fascinating.  Can you share the output you are collecting from the callback?

Sure, but via email rather than public forum? 

 

Have you used canvas.after?

No, not yet. I'm trying to provoke the problem in some repeatable way in it's current form before trying any fix to then try to see if it is then, indeed fixed.

 

What did you mean by: ‘it's definitely on add_widget()'d once.’ ?

sorry, typo -- I meant it's definitely only add_widget()'d once -- i.e. there is one a single call to add_widget for each item.

 

My mental model:
on calling add_widget(), the canvas code would be executed (scheduled to be executed).
from the app.run() loop, the canvas code would be executed if there was an event that could change the screen.

the second is true. the first doesn't happen (until the first event). 
Reply all
Reply to author
Forward
0 new messages