ControlList.selectItem crashes Kodi to Desktop if called in function
#1
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 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.
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)
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.
Developer for Shoko and Nakamori. Long time user of Kodi, before it was even called Kodi. My XBOX died long ago, but Windows is still just as broken and necessary. I obviously watch anime, given my first comment. Video games, manga, music, you name it.
Reply
#2
What version of Kodi are you running?
Reply
#3
Ah. Forgot that minor detail.... This happens in Kodi 17.6. I have no idea if it happens in Leia, but that has so many other changes to the Python interface that it's hard to say.
Developer for Shoko and Nakamori. Long time user of Kodi, before it was even called Kodi. My XBOX died long ago, but Windows is still just as broken and necessary. I obviously watch anime, given my first comment. Video games, manga, music, you name it.
Reply
#4
Two questions:
1. Are you sure the value of index is legal?
2. Are you sure a list control is being returned from your function and not the value None? You should test that the returned value is not None before executing select item.
Reply
#5
I answered those in the OP, but I'll reiterate. Yes, the only thing changing with these tests are the code shown. The index is the same and valid. The ControlList is returned successfully and is called.
Kodi catches it properly if you try to call an invalid index or None.selectItem().

EDIT: I'll also state that this is on a finalized list, ie not during a plugin building the list
Developer for Shoko and Nakamori. Long time user of Kodi, before it was even called Kodi. My XBOX died long ago, but Windows is still just as broken and necessary. I obviously watch anime, given my first comment. Video games, manga, music, you name it.
Reply
#6
(2019-03-27, 13:26)da3dsoul Wrote: I answered those in the OP, but I'll reiterate. Yes, the only thing changing with these tests are the code shown. The index is the same and valid. The ControlList is returned successfully and is called.
Kodi catches it properly if you try to call an invalid index or None.selectItem().

EDIT: I'll also state that this is on a finalized list, ie not during a plugin building the list
I've not experienced a problem using the selectItem method crashing in my addon under V17.6:
Python:

def onFocus(self, ctrlID):
    ctrl = self.getControl(ctrlID)
    if ctrlID == MAIN_LIST:
        ctrl.selectItem(0)

The above code is in a subclass of xbmcgui.WindowXMLDialog.
ctrlID is an integer representing the list control id and is used to get an instance of the list control.
The selectItem method of that instance is eventually called with an index value of zero and does not crash under V17.6.

Without seeing the context in which you are running your function, it's difficult to determine why your code is crashing.
Reply
#7
Interesting. I wonder if it's because you are getting it by ID? I thought I had finally narrowed down the reason, but maybe not...
Developer for Shoko and Nakamori. Long time user of Kodi, before it was even called Kodi. My XBOX died long ago, but Windows is still just as broken and necessary. I obviously watch anime, given my first comment. Video games, manga, music, you name it.
Reply
#8
Based on what you've posted, it appears that you are using a polling technique to obtain a reference to a list control in your addon. Whereas in my add-on, I'm responding to a focus event and using the supplied ctrlId parameter to obtain a reference to a list control.

Polling is more CPU intensive and is not as fast and not as efficient as event handling. My recommendation would be to use event handling in your add-on instead of polling.
Reply
#9
I'm not sure I can use events for this case. It has subclassed ListItems, but it's just a normal Kodi directory from a plugin, complete with addDirectoryItems and endOfDirectory. If there's a way to execute code on menu load when in a specific plugin, then that might work, but I don't know of such a way.
Developer for Shoko and Nakamori. Long time user of Kodi, before it was even called Kodi. My XBOX died long ago, but Windows is still just as broken and necessary. I obviously watch anime, given my first comment. Video games, manga, music, you name it.
Reply

Logout Mark Read Team Forum Stats Members Help
ControlList.selectItem crashes Kodi to Desktop if called in function0