2019-03-26, 12:01
This one is super weird. I assume it's another BS reason to hate Python, but I've no clue.
If this code is called from the same function as
If I do this, then it hard crashes Kodi to desktop. I couldn't find any useful info in the debug log or event viewer. The event viewer says error 1000 with garbage hex. After stepping through it in PyCharm, I found that it goes to get_list_control() properly, does the loop once, gets the control, returns it properly, and selectItem(index) is called on it. It crashes to desktop before returning from selectItem.
If this code is called from the same function as
control_list.selectItem(index)
, then it works, and all is well, except that the function looks super messy with a big while loop in the middle of it. Index is valid in both cases, and the while loop always gets it on the first try in my test and escapes, so that's not relevant atm.python:
elapsed = 0
interval = 250
wait_time = 4000
control_list = None
while True:
if elapsed >= wait_time:
break
try:
wind = xbmcgui.Window(xbmcgui.getCurrentWindowId())
control_list = wind.getControl(wind.getFocusId())
if isinstance(control_list, xbmcgui.ControlList):
break
except:
pass
xbmc.sleep(interval)
elapsed += interval
if control_list:
control_list.selectItem(index)
If I do this, then it hard crashes Kodi to desktop. I couldn't find any useful info in the debug log or event viewer. The event viewer says error 1000 with garbage hex. After stepping through it in PyCharm, I found that it goes to get_list_control() properly, does the loop once, gets the control, returns it properly, and selectItem(index) is called on it. It crashes to desktop before returning from selectItem.
Has anyone ever seen something like this? I can only imagine that it's a bug in the way that the python to C++ implementation handles passing a python object to the corresponding C++ one when it's passed through a function.python:def get_list_control():
elapsed = 0
interval = 250
wait_time = 4000
control_list = None
while True:
if elapsed >= wait_time:
break
try:
wind = xbmcgui.Window(xbmcgui.getCurrentWindowId())
control_list = wind.getControl(wind.getFocusId())
if isinstance(control_list, xbmcgui.ControlList):
break
except:
pass
xbmc.sleep(interval)
elapsed += interval
return control_list
control_list = get_list_control()
if control_list:
control_list.selectItem(index)