DropFile problem in RapaGUI

Report any Hollywood bugs here
Post Reply
User avatar
midwan
Posts: 74
Joined: Sun Jun 19, 2016 1:15 pm
Location: Sweden

DropFile problem in RapaGUI

Post 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.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: DropFile problem in RapaGUI

Post 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.
User avatar
midwan
Posts: 74
Joined: Sun Jun 19, 2016 1:15 pm
Location: Sweden

Re: DropFile problem in RapaGUI

Post by midwan »

Indeed, that makes sense. :)

Thank you for the help!
Post Reply