Author Topic: Checking object?  (Read 119 times)

HSE

  • Member
  • *****
  • Posts: 1379
  • <AMD>< 7-32>
Checking object?
« on: September 15, 2020, 06:40:55 AM »
Hi Biterider!

There is some defined way to know if pointed direccion is an object?

I have an spaghetti that apparently try to destroy objects previously destroyed  :biggrin:

Thanks.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 542
  • ObjAsm Developer
    • ObjAsm
Re: Checking object?
« Reply #1 on: September 16, 2020, 02:36:23 AM »
Hi HSE
As you know, a pointer to an object instance is simply a pointer to a memory location. You can try to check if you can see a pattern in memory, but it is difficult and error-prone.
I also had this problem and I solved it by setting the object pointer to NULL immediately after destroying it.
This way I got an exception when I accidentally tried to access it.

I hope this helps a bit  :rolleyes:

Biterider

HSE

  • Member
  • *****
  • Posts: 1379
  • <AMD>< 7-32>
Re: Checking object?
« Reply #2 on: September 16, 2020, 05:11:13 AM »
Hi Biterider!

You can try to check if you can see a pattern in memory, but it is difficult and error-prone.
Yes, I was thinking something like that. Perhaps was already maked...  :nie:

I also had this problem and I solved it by setting the object pointer to NULL immediately after destroying it. This way I got an exception when I accidentally tried to access it.
Yes, I have that exceptions from time to time  :biggrin:
Some problems arise when same object belong simultaneously to several lists or collections.
Fortunatelly I found yesterday problem, and I think I will not have that problem never more..  until tomorrow :biggrin:
Perhaps next time I will try to make something.
 
Thanks.

HSE


Biterider

  • Moderator
  • Member
  • *****
  • Posts: 542
  • ObjAsm Developer
    • ObjAsm
Re: Checking object?
« Reply #3 on: September 16, 2020, 03:40:13 PM »
Hi HSE
I suspect your problem is more architecture related.  :rolleyes:

I recently developed an object that I had a similar problem with. I put all the object instances that the control manages in a master list, that was responsible for the life cycle of these objects.
Additionally I implemented other lists to handle the logic of the control. These lists were XWCollections that only stored the instance pointers and did not destroy the object when an item of the list was deleted.

Regards, Biterider




HSE

  • Member
  • *****
  • Posts: 1379
  • <AMD>< 7-32>
Re: Checking object?
« Reply #4 on: September 17, 2020, 12:41:02 AM »
Hi Biterider!

I suspect your problem is more architecture related.  :rolleyes:
Exactly  :biggrin:

I recently developed an object that I had a similar problem with. I put all the object instances that the control manages in a master list, that was responsible for the life cycle of these objects.
I maked that collections  :thumbsup:

Additionally I implemented other lists to handle the logic of the control. These lists were XWCollections that only stored the instance pointers and did not destroy the object when an item of the list was deleted.
Just in case I maked:
Code: [Select]
Method Vector.Clean, uses xbx xsi xdx
    SetObject xsi
    mov xbx, [xsi].dCount
    mov xdi, [xsi].pItems
    or xbx, xbx
    jmp @@1
align ALIGN_CODE
@@0:
    mov POINTER ptr [xdi], NULL
    add xdi, sizeof POINTER
    dec xbx
@@1:
    jnz @@0
    m2z [xsi].dCount
MethodEnd

but in practical terms you only need:
Code: [Select]
mov [xax].Vector.dCount, 0
Regards. HSE