How to improve speed of drawing? Very slow scene view.
-
I made a script using
scene
module. Basically it shows a different "image" depending on horizontaltouch.location
.from scene import * import ui glyphsDict = {} # My dictionary with paths to draw class MyScene (Scene): def setup(self): self.myPath = ShapeNode(glyphsDict[1]) # first path to draw self.add_child(self.myPath) self.background_color = 'lightgrey' def touch_began(self, touch): x, y = touch.location z = int(x/(10.24/2)+1) self.myPath.path = glyphsDict[z] # Setting a new path to draw def touch_moved(self, touch): x, y = touch.location z = int(x/(10.24/2)+1) self.myPath.path = glyphsDict[z] # Setting a new path to draw run(MyScene())
Before that i did the same using
SpriteNode
and swapping textures. I had 200 .gif images 7KB each (1.4MB summed up) and while the app crashed from time to time i got a rather smooth result if i "loaded" all the images by slowly moving my finger across the screen.The version with
SpriteNode
and images looked like this: https://www.instagram.com/p/BSL9ea8g0dv/I thought i'd move to drawing paths and the code above reflects that. My path information is 200KB so 7 times smaller that all the .gif's i was loading before. But now the animation is super slow and looks like 2fps or is not reacting at all if i move my finger very fast. On the bright side, I don't see the app crashing anymore.
How can i improve on this? Why drawing paths is slower than loading images that are bigger?
-
https://gist.github.com/8fe4aa269b15a7071633e256456786ca
Here is an improved method, using KeyFrame animations.
Basically, you set up 5 or whatever refernces, add to a PathAnimation, and then provide the interpolation value (0..len(glyphs)).i have not tried installing your font yet. Might try UIFont.fontWithName_size_traits_(). or maybe need o set up fondDescriptor.
-
Can you please confirm if your iOS devices are 32 or 64 bit?
-
https://gist.github.com/c8b993ac42ede2574dc9f7cc26ebb1f4
and here is a version that uses your font file, and cleans things up a bit.I am on 32 bit -- ccc, is this crashing for you? If so, on what line? I think I got typedefs correct but I may have missed a few
-
Unfortunately @JonB I confirm that it crashes on 64 bit.
-
Which line is crashing? Do you have the fault handler installed?
-
https://gist.github.com/7a73b8c3abab4dc502ef2314574c6744
For some reason I was missing a slew of definitions. Try this one on 64bit...
-
@JonB i get "No method found for mutableCopy" on line 80
-
https://gist.github.com/80660624600c28c8e7812b15e0652568
How about this one....
-
@JonB this one raises the exception from line 15
-
can you paste the full traceback? Also, did you place the Panvaria.ttf file in the same folder? I probably should have mentioned that!
-
@JonB yes, i have the file in the same folder.
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 144, in <module> [glyphs_list, variation_values]=setupGlyphs(size=512,letter='e') File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 78, in setupGlyphs basefont = c.CGFontCreateWithDataProvider(provider); File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 15, in errcheck raise Exception('{} returned void pointer with args\n{}'.format(func.__name__,args)) Exception: CGFontCreateWithDataProvider returned void pointer with args (6242820560,)```
-
added a little extra diagnostics, and tried passing provider as objcinstancee.
https://gist.github.com/b4c3e011e768320753e3c54405c56380
-
@JonB here's the traceback
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 148, in <module> [glyphs_list, variation_values]=setupGlyphs(size=512,letter='e') File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 82, in setupGlyphs basefont = c.CGFontCreateWithDataProvider(provider); File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 15, in errcheck raise Exception('{} returned void pointer with args\n{}'.format(func.__name__,args)) Exception: CGFontCreateWithDataProvider returned void pointer with args (<b'__NSCFType': <CGDataProvider 0x17418b530>>,)```
-
How did yoy get the ttf into the device? i think this is saying the font file is invalid.
This version downloads the font directly
https://gist.github.com/7a766eb282c71bf7d27bd13fb4926482
-
@JonB there was indeed something wrong with the file. this script just crashes the app. is there a method to catch errors on crash?
-
@dgelessus has a pythonista_startup repo that installs a fault handler and uncaught exception handler which write to a fault log, so you can see which line (for segfaults and the like) or an objc stack trace in the case of objc errors (which often include a helpful message)
https://github.com/dgelessus/pythonista_startup
See the readme, there are several scripts here, personally I just use the enable_faulthandler one.
You could also set a breakpoint by long pressing in the debugger, and just keep single stepping until the crash happens.
-
https://gist.github.com/38a5434b4ebd28775dab08d181a00771
Here is a version that logs all cdll calls to glyphlog.txt. if you can post that someplace, we can see exactly what is crashing.
-
@JonB thank you for hints on debugging, definetely helpful.
Here's the error log: https://gist.github.com/5bac67b24317b5e5b4badc06bee1b1c5
-
whoops, I missed one of the definitions.
https://gist.github.com/a30ddae506762c96e533f98668ad46dd
This should do it now....maybeThought for a future improvement....a CDLL which prevents calling a function unless restype and argtypes have specifically been defined.
-
@JonB unfortunatelly: https://gist.github.com/5f53f356c0c85fa9525efd13a1000198