Solved Help with "Attempt to use invalid handle -1" error.
#1
Hi,

I'm getting the error "Attempt to use invalid handle -1" in my log file when using cetain parts of my plugin and am having a tough time working out why. I get the error when choosing a file contained within a folder or when invoking the search within the addon.

Snippet of the error when selecting a file:
Code:
14:07:38 T:12760   DEBUG: CInputManager::OnKey: return (0xf00d) pressed, action is Select
14:07:38 T:12760   DEBUG: XFILE::CPluginDirectory::RunScriptWithParams - calling plugin Hyper Launcher('plugin://plugin.hyper.launcher/','-1','?rom_path=C%3A%5Cemulation%5Croms%5CAtari+-+2600&launcher_script=C%3A%5CUsers%5Ctw%5CAppData%5CRoaming%5CKodi%5Cuserdata%5Caddon_data%5Cplugin.hyper.launcher%5Clauncher_scripts%5Crocketlauncher.bat&filename=3-D+Tic-Tac-Toe+%28USA%29&game_name=3-D+Tic-Tac-Toe+%28USA%29&foldername=Atari+2600&mode=file')
14:07:38 T:760   DEBUG: Thread LanguageInvoker start, auto delete: false
14:07:38 T:760    INFO: initializing python engine.
14:07:38 T:760   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): start processing
14:07:38 T:760   DEBUG: -->Python Interpreter Initialized<--
14:07:38 T:760   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): the source file to load is "C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py"
14:07:38 T:760   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): setting the Python path to C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher;C:\Program Files (x86)\Kodi\system\python\DLLs;C:\Program Files (x86)\Kodi\system\python\Lib;C:\Program Files (x86)\Kodi\python27.zip;C:\Program Files (x86)\Kodi\system\python\lib\plat-win;C:\Program Files (x86)\Kodi\system\python\lib\lib-tk;C:\Program Files (x86)\Kodi;C:\Program Files (x86)\Kodi\system\python;C:\Program Files (x86)\Kodi\system\python\lib\site-packages
14:07:38 T:760   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): entering source directory C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher
14:07:38 T:760   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): instantiating addon using automatically obtained id of "plugin.hyper.launcher" dependent on version 2.1.0 of the xbmc.python api
14:07:38 T:760 WARNING: Attempt to use invalid handle -1

When calling the plugin with the search option:
Code:
14:18:48 T:13420   DEBUG: ------ Window Deinit (DialogContextMenu.xml) ------
14:18:48 T:13420   DEBUG: XFILE::CPluginDirectory::RunScriptWithParams - calling plugin Hyper Launcher('plugin://plugin.hyper.launcher/','-1','?mode=search&addon_handle=3')
14:18:48 T:4808   DEBUG: Thread LanguageInvoker start, auto delete: false
14:18:48 T:4808    INFO: initializing python engine.
14:18:48 T:4808   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): start processing
14:18:48 T:4808   DEBUG: -->Python Interpreter Initialized<--
14:18:48 T:4808   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): the source file to load is "C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py"
14:18:48 T:4808   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): setting the Python path to C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher;C:\Program Files (x86)\Kodi\system\python\DLLs;C:\Program Files (x86)\Kodi\system\python\Lib;C:\Program Files (x86)\Kodi\python27.zip;C:\Program Files (x86)\Kodi\system\python\lib\plat-win;C:\Program Files (x86)\Kodi\system\python\lib\lib-tk;C:\Program Files (x86)\Kodi;C:\Program Files (x86)\Kodi\system\python;C:\Program Files (x86)\Kodi\system\python\lib\site-packages
14:18:48 T:4808   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): entering source directory C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher
14:18:48 T:4808   DEBUG: CPythonInvoker(9, C:\Users\tw\AppData\Roaming\Kodi\addons\plugin.hyper.launcher\default.py): instantiating addon using automatically obtained id of "plugin.hyper.launcher" dependent on version 2.1.0 of the xbmc.python api
14:18:48 T:4808 WARNING: Attempt to use invalid handle -1
14:18:48 T:4808   DEBUG: aaasearch

Plugin code:
Code:
See post #2

Anyone have any ideas as to why I'm getting the error? Thanks in advance.
Reply
#2
Setting the property isPlayable to true for the file type listitems within a folder gets rid of the 'Attempt to use invalid handle -1' error when selecting the entry (though I occasionally get a 'one or more items failed to play error' when launching the selected file item, but the invalid handle error doesn't prevent the plugin from working as should here).

But no matter what I try the 'search' element of the if/else statement fails to generate a list of items, with the 'Attempt to use invalid handle -1' error appearing multiple times in the log file. Code is ok, because if I set it so it runs within the first element ('None') of the if/else statement it displays the search results in a list. It is being launched from a folder via the context menu, so from my understanding a valid addon_handle should be forwarded and displaying a list of files should work. What has me stumped is that its not that different from 'folder' mode within the if/else statement, which works OK - the only real difference is the time it takes to generated the list. I have tried to reuse the original addon handle by passing it on as a argument within the url for use in the 'search' element to no avail.

Log file:
http://pastebin.com/AQSDZKqL

Updated plugin code:
http://pastebin.com/MKzPfLBw
Reply
#3
For plugin rules are the following:
- If a ListItem opens a lower lever list, it must have isFolder=True.
- If a ListItem calls a playback function that ends with setResolvedUrl, it must have setProperty('isPlayable', 'true') and IsFolder=False.
- If a ListItem does any other task except for mentioned above, is must have isFolder=False (and only this).

This way you won't have problems with invalid handles.
Reply
#4
Thanks Roman_V_M.

If I create a listitem for the 'search' element and run it from there a list is generated and search results are displayed as expected. While that works I would really like to launch 'search' via the context menu for several reasons: to keep the lists uncluttered (plus I'm not sure how having 'Search' as a listitem would work with regards to sorting of the lists) and to easily segregate the searches (search in the root folder searches all systems/sub folders, search in a sub folder only searches that system/folder).

I figure the rules you posted above don't apply to context menu items, but I did try out all three combos to no avail.

So I guess my question now is, is there anyway to launch an instance of my plugin via the context menu, with the RunPlugin() function, and retain the addon_handle and have a list generated?

A shortened version of what contained in my plugin (full version in post #2):
Code:
base_url = sys.argv[0]
contextMenuItems.append(('Search', 'XBMC.RunPlugin(%s?mode=search)' % (base_url) ,))
Reply
#5
I had a close look at advanced launcher and using the method from it:

contextMenuItems.append(('Search all systems', 'xbmc.ReplaceWindow(Videos,%s?mode=search)' % (base_url) ,))

instead of xbmc.runplugin does the trick!

Edit the above isnt perfect - it goes back to the root dir when going up a level.
The following method works a treat:
http://forum.kodi.tv/showthread.php?tid=80539
Reply
#6
(2016-01-27, 23:06)teeedubb Wrote: to keep the lists uncluttered (plus I'm not sure how having 'Search' as a listitem would work with regards to sorting of the lists)

According to my experience, list items with labels starting from non-alphabet/non-numeric characters do not count when sorting. At least it works for "<" and "[". This means that, for example, if you have an item named "<< Home" at the beginning of your list, then it will stay at the beginning even if you reverse sort order. So you can try something like "<Search>".
Reply
#7
Yeah good point. Will come in handy for for a "random" list item.
Reply

Logout Mark Read Team Forum Stats Members Help
Help with "Attempt to use invalid handle -1" error.0