Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3773

Dictionary Corruption

$
0
0

We are getting a very weird error when using a dictionary. Sometimes, the values become corrupted.
Here is an except from debugging the problem.

dim overalls(2) as string

dim d as new dictionary
dim pd as new mydictionary
dim d2 as new dictionary
dim d3 as new xojo.core.dictionary
me.gradedata = new mydictionary

dim overall as string = overalls(0)
dim cmyk as string = overalls(1)
dim spot as string = overalls(2)
me.gradedata.value("overall") = overall
d.value("overall") = overall
pd.value("overall") = overall
d2.Value("overall")="3"
d3.Value("overall")="3"

me.gradedata is a mydictionary class and is a subclass of dictionary. The others are just local variables for testing to compare.

overalls(2) is a string array containing (“3”,“”,“3”) and can be confirmed by looking in the IDE.

But, when I look at the dictionary, the values for the keys show as empty and the typeinfo of the value contains gibberish ‘UH��AVSI��H���!fH��L���fH�T�H�8’

We normally write the dictionary as a string to save it and have a loop to generate a string data for many of the types

dim attributestrings() as string
dim thiskey as variant
dim thisvalue as variant
for each thisentry as DictionaryEntry in d
  thiskey=thisentry.Key
  thisvalue=thisentry.Value
  
  Var ti As Introspection.Typeinfo = Introspection.GetType(thisvalue)
  
  if ti<>nil then
select case ti.name
case "string"
....
....
case "Folderitem"
  valuestring = encodehex(folderitem(thisvalue).SaveInfo(nil))
else
  if ti.IsPrimitive then
    //basic type
    attributestrings.Append(thiskey+chr(9)+EncodingToURLMBS(thisvalue))
  else
    break
    app.debugmessage("dictionary_string error mydictionary string for a type "+ti.fullname)
    valuestring="BADDATA"
  end if
end select

We get a breakpoint with it.fullname containing the above gibberish type when it goes wrong. Processing the same data again does not cause each time.

Back to the code above…
d, pd, d2 and d3 are all local variables.
Inspecting them in the IDE shows that dictionary d and d2 are both corrupt. The value of “overall” is empty and has the gibberish ti.fullname. How this can happen to a local variable, I really can’t understand. d2 has “3” directly allocated to it. d3, of type Xojo.Core.Dictionary is ok and contains a single entry with a key of “overall” and a value of “3”. Unfortunately, I can’t make mydictionary a subclass of Xojo.Core.Dictionary because there are many internal functions and plugins which require a ‘Dictionary class’, not ‘Xojo.Core.Dictionary’

Has anyone seen anything like this before?

I’m using Xojo2024r1.1 and Xojo2024r1. MBS 2023r4 and now 2024pr2 beta as a test

Regards,

Lee

12 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 3773

Trending Articles