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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on cythonized AnimationSystem #131

Merged
merged 8 commits into from Jun 14, 2016

Conversation

Projects
None yet
3 participants
@udiboy1209
Member

udiboy1209 commented May 7, 2016

Its my first time dealing with cython, so I dont know how my code will perform.

@Kovak @tito if you could do a sanity check on the code 馃槃! I will fix the build issues and push an example for testing soon.

Also, I don't know how to initialise a variable lenth array in cython which is causing some errors in the build.

@Kovak

This comment has been minimized.

Contributor

Kovak commented May 9, 2016

anim_comp.current_duration = 0
anim_comp.current_frame_index += 1
next_frame = <FrameStruct*>anim_comp.frames[anim_comp.current_frame_index]

This comment has been minimized.

@Kovak

Kovak May 10, 2016

Contributor

This is looking real good so far, here when we change model and texkey being used, we also want to perform manually the same check as done here: https://github.com/kivy/kivent/blob/master/modules/core/kivent_core/systems/renderers.pyx#L154

to make sure we rebatch if it is necessary

cdef MemoryBlock frames_block = MemoryBlock(
frame_count*sizeof(FrameStruct), sizeof(FrameStruct), 1)
frames_block.allocate_memory_with_buffer(frame_buffer)

This comment has been minimized.

@udiboy1209

udiboy1209 May 12, 2016

Member

@Kovak @tito I get a segfault at this line when I run the new example I added. Any clue whats up?

This comment has been minimized.

@tito

tito May 12, 2016

Member

Do you have the raw traceback? (you can debug with gdb --args python XXX, then "r" to start it, and "bt" when it crash)

This comment has been minimized.

@udiboy1209

udiboy1209 May 12, 2016

Member

@tito here:

#0  0x000000000000000a in ?? ()
#1  0x00007fffe7ea8630 in __pyx_f_11kivent_core_15memory_handlers_5block_11MemoryBlock_allocate_memory_with_buffer (__pyx_v_self=0x7fffd9fdccd0, __pyx_v_master_buffer=0x8fb4d0 <_Py_NoneStruct>)
    at kivent_core/memory_handlers/block.c:1162
#2  0x00007fffe22d0e61 in __pyx_pf_11kivent_core_9rendering_9animation_9FrameList___cinit__ (__pyx_v_name=<optimized out>, __pyx_v_model_manager=<optimized out>, __pyx_v_frame_buffer=<optimized out>, 
    __pyx_v_frame_count=<optimized out>, __pyx_v_self=0x7fffe0fa5e60) at ./kivent_core/rendering/animation.c:2022
#3  __pyx_pw_11kivent_core_9rendering_9animation_9FrameList_1__cinit__ (__pyx_kwds=<optimized out>, __pyx_args=<optimized out>, __pyx_v_self=0x7fffe0fa5e60) at ./kivent_core/rendering/animation.c:1888
#4  __pyx_tp_new_11kivent_core_9rendering_9animation_FrameList (t=<optimized out>, a=<optimized out>, k=<optimized out>) at ./kivent_core/rendering/animation.c:2900
#5  0x00000000004b6db3 in ?? ()
#6  0x00007fffe24d9280 in __Pyx_PyObject_Call (kw=0x0, arg=0x7fffe544e1b0, func=0x7fffe24d5900 <__pyx_type_11kivent_core_9rendering_9animation_FrameList>) at ./kivent_core/managers/animation_manager.c:2124
#7  __pyx_pf_11kivent_core_8managers_17animation_manager_16AnimationManager_4load_animation (__pyx_v_loop=<optimized out>, __pyx_v_frames=<optimized out>, __pyx_v_frame_count=<optimized out>, __pyx_v_name=<optimized out>, 
    __pyx_v_self=0x7fffe56d3410) at ./kivent_core/managers/animation_manager.c:1427
#8  __pyx_pw_11kivent_core_8managers_17animation_manager_16AnimationManager_5load_animation (__pyx_v_self=0x7fffe56d3410, __pyx_args=<optimized out>, __pyx_kwds=<optimized out>)
    at ./kivent_core/managers/animation_manager.c:1387
#9  0x00000000004c4d5a in PyEval_EvalFrameEx ()
#10 0x00000000004ca39f in PyEval_EvalFrameEx ()
#11 0x00000000004c2e05 in PyEval_EvalCodeEx ()
#12 0x00000000004ded4e in ?? ()
#13 0x00007fffe28ef5a9 in __Pyx_PyObject_Call (kw=0x0, arg=0x7fffe0fac9d0, func=0x7fffe54510c8) at ./kivent_core/gameworld.c:13802
#14 __Pyx__PyObject_CallOneArg (func=func@entry=0x7fffe54510c8, arg=arg@entry=0x7fffe80ca670) at ./kivent_core/gameworld.c:13839
#15 0x00007fffe2901f2d in __Pyx_PyObject_CallOneArg (arg=0x7fffe80ca670, func=0x7fffe54510c8) at ./kivent_core/gameworld.c:13853
#16 __pyx_pf_11kivent_core_9gameworld_9GameWorld_6init_gameworld (__pyx_self=<optimized out>, __pyx_v_callback=<optimized out>, __pyx_v_list_of_systems=<optimized out>, __pyx_v_self=<optimized out>)
    at ./kivent_core/gameworld.c:5916
#17 __pyx_pw_11kivent_core_9gameworld_9GameWorld_7init_gameworld (__pyx_self=<optimized out>, __pyx_args=<optimized out>, __pyx_kwds=<optimized out>) at ./kivent_core/gameworld.c:5630
#18 0x00000000004b1153 in PyObject_Call ()
#19 0x00000000004f4c3e in ?? ()
#20 0x00007fffe28ef86a in __Pyx_PyObject_Call (kw=0x7fffe0fb74b0, arg=0x7fffe9dc1250, func=0x7fffe81bf5f0) at ./kivent_core/gameworld.c:13802
#21 __pyx_lambda_funcdef_lambda (__pyx_v_dt=<optimized out>, __pyx_self=<optimized out>) at ./kivent_core/gameworld.c:5706
#22 __pyx_pw_11kivent_core_9gameworld_9GameWorld_14init_gameworld_lambda (__pyx_self=<optimized out>, __pyx_v_dt=<optimized out>) at ./kivent_core/gameworld.c:5652
#23 0x00000000004b1153 in PyObject_Call ()
#24 0x00000000004ca5ca in PyEval_EvalFrameEx ()
#25 0x00000000004ca39f in PyEval_EvalFrameEx ()
#26 0x00000000004ca39f in PyEval_EvalFrameEx ()
#27 0x00000000004ca39f in PyEval_EvalFrameEx ()
#28 0x00000000004ca39f in PyEval_EvalFrameEx ()
#29 0x00000000004ca39f in PyEval_EvalFrameEx ()
#30 0x00000000004ca39f in PyEval_EvalFrameEx ()
#31 0x00000000004c2e05 in PyEval_EvalCodeEx ()
#32 0x00000000004ca6b5 in PyEval_EvalFrameEx ()
#33 0x00000000004ca39f in PyEval_EvalFrameEx ()
#34 0x00000000004c2e05 in PyEval_EvalCodeEx ()
#35 0x00000000004c2ba9 in PyEval_EvalCode ()
#36 0x00000000004f20ef in ?? ()
#37 0x00000000004eca72 in PyRun_FileExFlags ()
#38 0x00000000004eb1f1 in PyRun_SimpleFileExFlags ()
#39 0x000000000049e18a in Py_Main ()
#40 0x00007ffff7811830 in __libc_start_main (main=0x49daf0 <main>, argc=2, argv=0x7fffffffde48, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde38) at ../csu/libc-start.c:291
#41 0x000000000049da19 in _start ()

I don't think it reveals a lot though 馃槙

self._animations = {}
def allocate(self, master_buffer, config_dict):
cdef MemoryBlock memory_block = MemoryBlock(self.allocation_size, 1, 1)

This comment has been minimized.

@Kovak

Kovak May 12, 2016

Contributor

This is never assigned to self.memory_block, causing your later call to creating a FrameList to pass in None as the memory_block

This comment has been minimized.

@udiboy1209

udiboy1209 May 12, 2016

Member

Ohh! nice catch! Was this evident from the gdb stack trace ?

This comment has been minimized.

@Kovak

Kovak May 12, 2016

Contributor

Yep!

#1 0x00007fffe7ea8630 in __pyx_f_11kivent_core_15memory_handlers_5block_11MemoryBlock_allocate_memory_with_buffer (__pyx_v_self=0x7fffd9fdccd0, __pyx_v_master_buffer=0x8fb4d0 <_Py_NoneStruct>) at kivent_core/memory_handlers/block.c:1162

Notice how the master buffer is actually a _Py_NoneStruct, at least if I'm reading this right that was the tip off that made me go look for the None

frame = frame_list[current_index]
frame_data = <FrameStruct*>frame.frame_pointer
if current_index != <unsigned int>-1 and anim_comp.dirty:

This comment has been minimized.

@Kovak

Kovak May 15, 2016

Contributor

we should switch this logic so that it occurs after the below logic that sets a comp to dirty, that way it occurs immediately after it happening instead of waiting a frame.

@udiboy1209 udiboy1209 changed the title from [WIP] Initial work on cythonized AnimationSystem to Initial work on cythonized AnimationSystem May 19, 2016

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 6, 2016

Hi @udiboy1209

I have added a new GameManager api. You will need to inherit from GameManager and implement the allocate function if you wish to grab some memory from the master buffer.

#140 is the PR with the new feature.

Essentially somewhere before calling GameWorld.allocate you should call GameWorld.register_manager. This could typically be done in the init of a GameSystem or in some user controlled code depending on use case.

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 12, 2016

udiboy1209: Getting an error with the twinkling stars example. Make sure you are testing your code in python 2 and python 3.

 Exception ignored in: 'kivent_core.rendering.animation.FrameList.__dealloc__'
 AttributeError: 'kivent_core.rendering.animation.FrameList' object has no attribute 'frame_buffer'
[INFO              ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "main.py", line 109, in <module>
     YourAppNameApp().run()
   File "C:\Python34\lib\site-packages\kivy\app.py", line 828, in run
     runTouchApp()
   File "C:\Python34\lib\site-packages\kivy\base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 633, in mainloop
     self._mainloop()
   File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 388, in _mainloop
     EventLoop.idle()
   File "C:\Python34\lib\site-packages\kivy\base.py", line 327, in idle
     Clock.tick()
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 521, in tick
     self._process_events()
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 653, in _process_events
     event.tick(self._last_tick, remove)
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 412, in tick
     ret = callback(self._dt)
   File "kivent_core\gameworld.pyx", line 281, in kivent_core.gameworld.GameWorld.init_gameworld.lambda (kivent_core/gameworld.c:5896)
   File "kivent_core\gameworld.pyx", line 278, in kivent_core.gameworld.GameWorld.init_gameworld (kivent_core/gameworld.c:6106)
   File "main.py", line 29, in init_game
     self.load_animations()
   File "main.py", line 57, in load_animations
     animation_manager.load_animation('star-animation-%d' % i, 3, animation_frames)
   File "kivent_core\managers\animation_manager.pyx", line 55, in kivent_core.managers.animation_manager.AnimationManager.load_animation (kivent
core/managers/animation_manager.c:1742)
   File "kivent_core\rendering\animation.pyx", line 60, in kivent_core.rendering.animation.FrameList.__cinit__ (kivent_core/rendering/animation.
:2144)
 TypeError: Expected str, got bytes
@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jun 12, 2016

@Kovak I'm having issues setting up a working python3 environment for kivy so I can not test this new change. But I think the latest commit should fix it. It would be great if you can test this today, else I will test it by tomorrow and report.

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 12, 2016

It looks like the tmp/anim.json file is missing. You should move it to where all the other assets for examples are and merge it.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jun 12, 2016

@Kovak is /tmp/anim.json giving a problem, because it only saves the animation to it as a test, It loads animations from assets/animations.json

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 13, 2016

Looks like there is some error in save_animations:

Traceback (most recent call last):
   File "main.py", line 109, in <module>
     YourAppNameApp().run()
   File "C:\Python34\lib\site-packages\kivy\app.py", line 828, in run
     runTouchApp()
   File "C:\Python34\lib\site-packages\kivy\base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 633, in mainloop
     self._mainloop()
   File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 388, in _mainloop
     EventLoop.idle()
   File "C:\Python34\lib\site-packages\kivy\base.py", line 327, in idle
     Clock.tick()
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 521, in tick
     self._process_events()
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 653, in _process_events
     event.tick(self._last_tick, remove)
   File "C:\Python34\lib\site-packages\kivy\clock.py", line 412, in tick
     ret = callback(self._dt)
   File "kivent_core\gameworld.pyx", line 281, in kivent_core.gameworld.GameWorld.init_gameworld.lambda (kivent_core/gameworld.c:5896)
   File "kivent_core\gameworld.pyx", line 278, in kivent_core.gameworld.GameWorld.init_gameworld (kivent_core/gameworld.c:6106)
   File "main.py", line 32, in init_game
     self.save_animations()
   File "main.py", line 63, in save_animations
     '/tmp/anim.json')
   File "kivent_core\managers\animation_manager.pyx", line 100, in kivent_core.managers.animation_manager.AnimationManager.save_to_json (kivent
ore/managers/animation_manager.c:2772)
 FileNotFoundError: [Errno 2] No such file or directory: '/tmp/anim.json'

I believe we need to check for and create the file if it is not existing.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jun 13, 2016

Ohh you're on windows! No /tmp/ dir there 馃槢! I'll fix it right now.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jun 13, 2016

@Kovak fixed, can you check again.

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 13, 2016

Excellent, running now.

Any idea about this message in the log:

[0x7FF802404450] ANOMALY: meaningless REX prefix used
[0x7FFFEA175790] ANOMALY: meaningless REX prefix used

Never seen it before

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 13, 2016

This could be related to my latest GPU drivers, doesn't look like anything we caused.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jun 13, 2016

I don't get that log message on my laptop, if its your drivers other examples might give the same message.

@Kovak Kovak merged commit c606c04 into kivy:2.2-dev Jun 14, 2016

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jun 14, 2016

great work!

@udiboy1209 udiboy1209 deleted the udiboy1209:animation_system branch Jun 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment