Bug? Me in class module

Informatix

Expert
Licensed User
Longtime User
Hello,

In one of my classes, "Me" returns N/A instead of the reference to the instance. It seems it does not like the type of some data.

This code reproduces the issue (it requires SimpleGameEngine):
For main:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    Dim Exped(4) As clsExpedition
    Exped(0).Initialize
End Sub

For clsExpedition:
B4X:
Sub Class_Globals
    Public Position As sgePoint2D
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    Log("InitMe=" & Me)
End Sub
 

Informatix

Expert
Licensed User
Longtime User
There is no bug here. The toString method inside sgePoint2D throws an exception because the internal point is null. You need to add a check for this in the toString method.
I never log the result of toString when the object is uninitialized, but that will be fixed however on my side. Thanks for noticing it.
Anyway, could you return the reference of the instance if toString fails? N/A is of no use.
In the real program, some of the class objects are intentionnaly not initialized in Initialize (the main reason for some of them is because they use a lot of memory and they are only initialized when they are really required; another reason is that my class has two states that can be checked by the program: partially initialized and fully initialized, and the program acts differently depending on the state).

You could have made sgePoint2D a wrapper object as it only has a single instance member.
The code sent is not a real case. The complete class has more than 20 members.
 
Top