Page 1 of 1

DropFile problem in RapaGUI

Posted: Mon May 01, 2017 3:18 pm
by midwan
I've been testing the DropFile msg.attribute in RapaGUI with Hollywood 7, and I've found a behavior that might be a bug:

The msg.triggervalue is supposed to be a table according to the docs, so I should be able to pass it to my Function that expects one to populate a listview.
However, if I do that I get a crash when Hollywood tries to iterate through the table items, complaining that the table is not initialized!

If I enumerate through the items at the event level and populate my listview there, it works. If I try to pass the msg.triggervalue as a parameter, it fails.

Code samples:

Given this Function:

Code: Select all

/*
** Adds a list of files in the Playlist listview
*/
Function p_InsertFilesInList(files)
	If files[0] = "" Then Return
	Local c = 0
	While files[c] <> ""
		moai.DoMethod("lv", "insert", "bottom", 9, files[c])
		c = c + 1
	Wend
	moai.Set("lv", "active", "Top")
EndFunction
This works:

Code: Select all

Case "DropFile":
	For Local k = 0 To ListItems(msg.triggervalue)-1 Do moai.DoMethod("lv", "insert", "bottom", 9, msg.triggervalue[k])
But this fails:

Code: Select all

Case "DropFile":
	p_InsertFilesInList(msg.triggervalue)
This also fails:

Code: Select all

Case "DropFile":
        Local temp = CopyTable(msg.triggervalue)
	p_InsertFilesInList(temp)
The above feels like a bug to me, as I would expect that the "msg.triggervalue" is a normal, initialized table I can go through.

Re: DropFile problem in RapaGUI

Posted: Tue May 02, 2017 9:46 pm
by airsoftsoftwair
The bug is in your code. This code snippet...

Code: Select all

While files[c] <> ""
      moai.DoMethod("lv", "insert", "bottom", 9, files[c])
      c = c + 1
Wend
...will end up accessing an uninitialized table element and throw an error then because you're simply incrementing "c" without checking for the table size. Use a For() loop with ListItems() instead to make sure you don't access elements outside the table's bounds.

Re: DropFile problem in RapaGUI

Posted: Wed May 03, 2017 9:29 pm
by midwan
Indeed, that makes sense. :)

Thank you for the help!