Dim var2 As type2 At VarPtr(var1)
issueid=317 24-09-2011 20:28
Member
Number of reported issues by dcromley: 6
Dim var2 As type2 At VarPtr(var1)
I get unexpected results

Hi,
As always, this is a very interesting site. You've done a lot. 1.8.9.0 is great!.

I want to access an array 2 different ways. So I do a " Dim var2 As type2 At VarPtr(var1)"
That's kind of like an "overlay", right?
Can you explain why I get "111222222444" instead of 111222333444"?
  Uses "console"

  Type type1
    m(2,2) As Long
  End Type        
  
  Type type2
    i1 As Long
    i2 As Long
    i3 As Long
    i4 As Long
  End Type
  
  Dim var1 As type1
  Dim var2 As type2 At VarPtr(var1)            
  
  var2.i1=111
  var2.i2=222
  var2.i3=333
  var2.i4=444
  PrintL var1.m(1,1) & var1.m(1,2) & var1.m(2,1) & var1.m(2,2)
  Console_WaitKey
Issue Details
Issue Number 317
Project thinBasic
Category Unknown
Status Fixed
Priority Unknown
Affected Version 1.8.9
Fixed Version (none)
Milestone (none)
Users able to reproduce bug 0
Users unable to reproduce bug 0
Assigned Users (none)
Tags (none)




25-09-2011 12:30
thinBasic author
I'm checking

25-09-2011 12:36
Super Moderator
It seems the issue is related not to the overlay process itself, but to multidimensional arrays inside UDT.
Multidimensional array "normal" variables seem to work okay:
Uses "console"
 
Type type1
  m(2,2) As Long
End Type       
 
Type type2
  i1 As Long
  i2 As Long
  i3 As Long
  i4 As Long
End Type 

Type type3
  m(4) As Long
End Type 

Dim m(2,2) As Long 
Dim var1 As type1
Dim var2 As type2 
Dim var3 As type3 
Dim sJoined As String

m(1,1) = 111
m(1,2) = 222
m(2,1) = 333
m(2,2) = 444 
sJoined = m(1,1) & m(1,2) & m(2,1) & m(2,2)     
PrintL sJoined, IIf$(sJoined = "111222333444", "OK", "PROBLEM")
 
var1.m(1,1) = 111
var1.m(1,2) = 222
var1.m(2,1) = 333
var1.m(2,2) = 444      
sJoined =  var1.m(1,1) & var1.m(1,2) & var1.m(2,1) & var1.m(2,2)
PrintL sJoined, IIf$(sJoined = "111222333444", "OK", "PROBLEM")

var2.i1=111
var2.i2=222
var2.i3=333
var2.i4=444
sJoined = var2.i1 & var2.i2 & var2.i3 & var2.i4
PrintL sJoined, IIf$(sJoined = "111222333444", "OK", "PROBLEM")

var3.m(1) = 111
var3.m(2) = 222
var3.m(3) = 333
var3.m(4) = 444   
sJoined = var3.m(1) & var3.m(2) & var3.m(3) & var3.m(4)
PrintL sJoined, IIf$(sJoined = "111222333444", "OK", "PROBLEM")

Console_WaitKey

25-09-2011 13:03
thinBasic author
Yes, bug is confirmed.

Attached two debug images.
The positive fact seems that data is stored correctly
The negative fact is that data is not retrieve correctly.

I will work on that.
Eros

25-09-2011 20:20
Member
Thank you (as usual) for the quick response and the further analysis.
Since matrix storage is column-order, my expectation should have been
111333222444 instead of 111222333444 anyhow.
But yes, the problem is apparently multi-dimension arays within UDT's.
Uses "console"
  
Type type2
  i1 As Long
  i2 As Long
  i3 As Long
  i4 As Long
End Type
 
Dim m(2,2) As Long
Dim var2 As type2 At VarPtr(m(1,1))  
Dim sJoined As String
 
m(1,1) = 111
m(1,2) = 222
m(2,1) = 333
m(2,2) = 444
sJoined = var2.i1 & var2.i2 & var2.i3 & var2.i4 
PrintL sJoined, IIf$(sJoined = "111222333444", "OK", "PROBLEM(Not)")
PrintL sJoined, IIf$(sJoined = "111333222444", "OK", "PROBLEM")
Console_WaitKey

18-10-2011 21:27
thinBasic author
I think I've fixed this case.
In case someone want to test new thinCore.Dll engine let me know and I will attach new 1.9 core

19-10-2011 11:17
Super Moderator
I would like to test it, if possible


Petr

19-10-2011 16:54
Member
Me too (or is it " I also")

19-10-2011 20:09
thinBasic author
Attached to the bottom of this thread.
Keep your \thinBasic\thinCore.dll before copying this new one into \thinBasic\ directory

Thanks for testing.
Let me know.
Eros

19-10-2011 22:12
thinBasic author
In any case consider that thinBasic arrays are organized in memory following column-order so the below example will not result into 111222333444 but into 111333222444

Uses "console"
 
Type type1
  m(2,2) As Long
End Type       
 
Type type2
  i1 As Long
  i2 As Long
  i3 As Long
  i4 As Long
End Type
 
Dim var1 As type1
Dim var2 As type2 At VarPtr(var1)            
 
var2.i1=111
var2.i2=222
var2.i3=333
var2.i4=444
PrintL var1.m(1,1) & var1.m(1,2) & var1.m(2,1) & var1.m(2,2)
Console_WaitKey

20-10-2011 11:12
Super Moderator
The fix seems to work, but it caused side effect in one of my scripts I use at work - it gives me false positive error "Variable or array must be a string type" for this line of code:
String events(32) 
Control Add COMBOBOX, hDlg, %cbEvent, events, 110, 10, 200, 200, %CBS_DROPDOWNLIST    ' -- RTE caused here
It might have root in other place of code. I will try to prepare minimal exampe this evening.


Petr

20-10-2011 12:06
thinBasic author
Stop Petr, do not vaste your time. It is not related to this fix, I know what it is your RTE

Do you remember when I asked you about changing equates of internat data type representation?
UI module is directly connected to this and if you use 1.9 version of Core you need to have all other modules 1.9 as well.

Important is that you confirm this fix is now gone.
I need to create a full 1.9 setup and send to you.

20-10-2011 15:02
Super Moderator
Hi Eros,

the udt arrays seem to be okay here - tested 1D, 2D, 3D case.


Petr

20-10-2011 16:42
Member
Just to let you know, I'll be gone for a week. That's why I'm not contributing here.
Thanks to you (and all of your staff?) for a great product.

30-10-2011 03:53
Member
I'm back.
The fix gives me what I wanted -- great!
I can access an array by indexes, by rows, and by element names.

But in the process of demoing how great it is, I hit a problem.
In the following, I commented out the problem statements.
I think the arrays in the UDT should be able to be loaded the same as non-UDT arrays?

This is really low priority. I just came across it by accident.
Uses "console"

Type typem22
  m(2,2) As Single
End Type   

Type typev1to4
  v1 As Single
  v2 As Single
  v3 As Single
  v4 As Single
End Type  

Global m22A(2,2) As Single
Global v1to4A As typev1to4 At VarPtr(m22A(1,1))
Global m22B As typem22
Global v1to4B As typev1to4 At VarPtr(m22B.m(1,1))
Global sJoined As String

m22A      = 11,12, 21,22 ' column order
m22A(1,1) = 11,12, 21,22 ' column order
sJoined = v1to4A.v1 & v1to4A.v2 & v1to4A.v3 & v1to4A.v4
PrintL sJoined, IIf$(sJoined = "11122122", "OK (column)", "PROBLEM")

m22A      = [11,12, 21,22] ' row order
m22A(1,1) = [11,12, 21,22] ' row order
sJoined = v1to4A.v1 & v1to4A.v2 & v1to4A.v3 & v1to4A.v4
PrintL sJoined, IIf$(sJoined = "11211222", "OK (row)", "PROBLEM")

'm22B.m      =  11,12, 21,22  ' column order ' problem with this usage
 m22B.m(1,1) =  11,12, 21,22  ' column order
sJoined = v1to4B.v1 & v1to4B.v2 & v1to4B.v3 & v1to4B.v4
PrintL sJoined, IIf$(sJoined = "11122122", "OK (column)", "PROBLEM")

'm22B.m      = [11,12, 21,22] ' row order ' can't get loaded in row order
'm22B.m(1,1) = [11,12, 21,22] ' row order ' can't get loaded in row order

Console_WaitKey

30-10-2011 08:02
thinBasic author
That is not supported so ATM is not a bug
You are right, behave should be the same so I will add as feature request
http://www.thinbasic.com/community/p...hp?issueid=330

PS: to keep thinks organized, please open new bug/feature requests otherwise nesting requests or bugs into bugs it will be difficult to follow them and I can miss something
Thanks
Eros

+ Reply