STRUCT-DOUBLE crashes when assigning integer
Description
If struct contains field of type Double, then LB crashes attempting to write integer value into that field with error message "a non-continuable protection violation has occurred. Check ERROR.LOG file." Integer could just happen as calculation result.
Example code to demonstrate the bug.
struct x, dbl as double x.dbl.struct = 1.1 '<-- ok y = 0.3+0.7 'happens to be integer value 'x.dbl.struct = y '<-- crash if uncommented
Example code to work around the bug.
It looks like we can force LB to consider number Double without changing (does not work if y*(1+1e-20) saved in temporary variable)
struct x, dbl as double x.dbl.struct = 1.1 '<-- ok y = 0.3+0.7 'happens to be integer value 'x.dbl.struct = y '<-- crash x.dbl.struct = y*(1+1e-20) '<- does not crash, 'and does not change y value print x.dbl.struct if x.dbl.struct = y then print "double in struct = y"
Another Example code to work around the bug.
'Use the Using() function to create a double
'from an integer
Struct myStruct, value As double
myStruct.value.struct = Val(Using("#.#", 0))
Print myStruct.value.struct
'Or set up a function, but you have
'to use Val() to get the double
myStruct.value.struct = Val(Dbl$(0))
Print myStruct.value.struct
Function Dbl$(val)
Dbl$ = Using("#.#", val)
End Function
'Creating a numeric return function
'will not work as LB will automatically
'turn the number back into an integer
''''''''''This will NOT work'''''''''
'Function Dbl(val)
' Dbl = Val(Using("#.#", val))
'End Function