Bug? Me in class module

Discussion in 'B4J Bugs & Wishlist' started by Informatix, Aug 3, 2017.

Similar threads

B4J Tutorial Pagination Container
B4J Tutorial Accordion container
B4J Tutorial [B4X] Resumable Subs - Sleep / Wait For
B4J Tutorial SQL Tutorial
B4J Tutorial Unhandled exceptions
B4J Library [custom view] SearchView
  1. Informatix

    Informatix Expert Licensed 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:
    Code:
    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.Show
        
    Dim Exped(4As clsExpedition
        Exped(
    0).Initialize
    End Sub
    For clsExpedition:
    Code:
    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
     
  2. Informatix

    Informatix Expert Licensed User

    I forgot to mention that's an issue with Log() (when I debug, I cannot know what's the concerned instance).
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the output?

    Does it work properly except of the logging issue?
     
  4. Informatix

    Informatix Expert Licensed User

    The output:
    InitMe=N/A

    Usually, Log() returns the result of toString or the reference.
    Except the logging issue, "Me" works as expected.
     
  5. Informatix

    Informatix Expert Licensed User

    In fact, any reference to the class is logged as N/A. It makes debugging with Log() impossible.
    @Erel When do you expect to release the fix?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't know yet.

    Can you upload a small project that reproduces this issue (with minimum dependencies)?
     
  7. Informatix

    Informatix Expert Licensed User

    See post #1, just copy/paste
     
  8. Informatix

    Informatix Expert Licensed User

    Here's the project. It requires only jSimpleGameEngine.
    Note that the sgePoint2D class used in clsExpedition has a toString method so there should be no problem to output its content.
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed 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.

    You could have made sgePoint2D a wrapper object as it only has a single instance member.
     
  10. Informatix

    Informatix Expert Licensed User

    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).

    The code sent is not a real case. The complete class has more than 20 members.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    It will return the class name with the identity hash.
     
    Informatix likes this.
Loading...