AutoGenerated IDs zero out in saved tables

Report any Hollywood bugs here
Post Reply
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

AutoGenerated IDs zero out in saved tables

Post by NathanH »

Hi,

I use Hollywood 8.0 on WinUAE with OS3.9 and AROS i-386. The following code saves some auto-generated brush ids in a table, prints them, saves the table, restores the table, and then prints the ids. The ids are zero when reprinted while I expected them to be saved and restored. I think I can find a workaround for my project but if this worked things would be much easier. It looks like a bug to me. Thanks.

@DISPLAY {hidden=True}

;global declarations
file$="SYS:System/Shell.info" ;path to a picture file; I've got an icon datatype
a={}

;load it three times
Function p_LoadBrushes()
a[0]=LoadBrush(Nil, file$)
a[1]=LoadBrush(Nil, file$)
a[2]=LoadBrush(Nil, file$)
EndFunction

Function p_BrushIds()
Local qty=ListItems(a)

DebugPrint("BrushIds, qty=", qty)
For Local i=0 To qty-1
DebugPrint(a)
Next
EndFunction

Function p_SaveTable()
OpenFile(1, "test", #MODE_WRITE)
WriteTable(1, a)
CloseFile(1)
EndFunction

Function p_RestoreTable()
a=Nil
CollectGarbage()

OpenFile(1, "test", #MODE_READ)
a=ReadTable(1)
CloseFile(1)
EndFunction

;execute

p_LoadBrushes()
p_BrushIds()
p_SaveTable()
p_RestoreTable()
p_BrushIds()

End()

HOLLYWOOD BRUSHIDTEST.HWS
BrushIds, qty= 3
UserData: 11dab9dc
UserData: 11dad0ec
UserData: 11dad50c
BrushIds, qty= 3
0
0
0
Tipsi
Posts: 21
Joined: Sun Feb 14, 2010 6:06 pm
Location: Switzerland

Re: AutoGenerated IDs zero out in saved tables

Post by Tipsi »

Hi NathanH

In the function p_RestoreTable() you have
deleted the table a. You have to declare it
as a table again:

Code: Select all

Function p_RestoreTable()
  a=Nil            ;delete the Table
  CollectGarbage()
  a={}             ;declare the Table again

  OpenFile(1, "test", #MODE_READ)
  a=ReadTable(1)
  CloseFile(1)
EndFunction
Griessli
Tipsi
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

Re: AutoGenerated IDs zero out in saved tables

Post by NathanH »

Thanks for wanting to help! You are spreading misinformation, however. Functions that return tables will make the variable into a table so you don't do "a={}" first. You can see below excerpts from the documentation for ReadTable, GetCommandLine, and RemoveItem that you don't declare a variable as a table first. I've bolded the undeclared variables for you. Also, you might want to try your suggestion to see if it actually solves the problem in the original message before responding. It doesn't fix this bug.

ReadTable:
EXAMPLE
mytable = {1, 2, 3, 4, 5,
"Hello World",
x = 100, y = 150,
subtable = {10, 9, 8, 7},
mulfunc = Function(a, b) Return(a*b) EndFunction
}
OpenFile(1, "table.bin", #MODE_WRITE)
WriteTable(1, mytable)394
Hollywood manual
CloseFile(1)
OpenFile(1, "table.bin", #MODE_READ)
newtable = ReadTable(1)
CloseFile(1)


GetCommandLine:
EXAMPLE
args, count = GetCommandLine()
NPrint("Number of arguments:", count)
For Local k = 0 to count - 1
NPrint("Arg #", k, ":", args[k].arg, "Param:", args[k].param)
Next

RemoveItem:
EXAMPLE
a = {1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10}
e = RemoveItem(a, 7)
For k = 1 To ListItems(a) Do Print(a[k - 1] .. " ")
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: AutoGenerated IDs zero out in saved tables

Post by PEB »

@NathanH

The behavior that you noticed is documented in the Hollywood history (https://hollywood-mal.com/docs/html/hol ... story.html) under Version 4.0 (28-Feb-09).

Even if the restored table maintained the original #LIGHTUSERDATA, you still might not be able to use that in your project, depending on what you plan on doing (since completely new and different identifiers of the type #LIGHTUSERDATA would be assigned every time).

How were you hoping to use the auto-generated brush IDs from the restored table in your project?
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: AutoGenerated IDs zero out in saved tables

Post by jPV »

Shouldn't

Code: Select all

DebugPrint(a)
be

Code: Select all

DebugPrint(a[i])
in your initial example, to get the result you pasted? (Edit: seems that italics was triggered with the [ i ], remember to use the code tag for code)

I don't think ids should be saved/restored, because aren't they dynamic and generated per session, so why do you want to save the ids at all?
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

Re: AutoGenerated IDs zero out in saved tables

Post by NathanH »

Thanks, it works that way by design. I was saving the table when I open up prefs window to restore if a user hits "Cancel" from within prefs. There's plenty of workarounds. I just wasn't counting on this not working as I expected.

On my computer, the code is DebugPrint(a). Not sure how that changed when copying it to the message.

Thanks again for your eagle eye. I never would have found that in the change logs.

NathanH
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: AutoGenerated IDs zero out in saved tables

Post by airsoftsoftwair »

PEB has already pointed out why this can't work. To add to this, it's impossible to save and restore variables of type #LIGHTUSERDATA and #USERDATA because they're basically just memory pointers and as such they are only valid in case they have been properly allocated.
Post Reply