Closing application

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Chiara
Posts: 30
Joined: Thursday 20 September, 2012 - 09:40

Closing application

Post by Chiara »

Good evening,

I have a problem when I close the attached model.
If I try to close the model, the application returns an error on the "model" atom. I understood that the problem is on the global variable, and probably because, in the model tree, the atom that I try to destroy has been already destroyed by the closing routine.
I attached a simple model, but the error is on a customized library. In this case, I tried to set all the global variables equal to 0 before closing the ED.app but without success.
What can I do?

Thanks
Attachments
closingmodel.mod
(14.32 KiB) Downloaded 278 times
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Closing application

Post by HarryBunnik »

Ha Chiara,

The problem lies indeed in the global variable "ciao" that you have created on the Source.

This variable "ciao" is pointing to the Source and on destruction of the Sink you try to destroy the source "DestroyAtom(ciao)" OnDestruction. When you are closing down your model, all is being destroyed and the OnDestruction of each atom in your model is executed. As a result the OnDestruction of the Sink is destroying the Source (as requested).

However the general closure of the model also tried to destroy the (by then no longer existing) Source. Since it cant find it, it throws an error message. So actually you're the first destroying it.

What do you try to realize with the code On Destruction? In the moment, if you delete the Sink, the source is automatically deleted as well. Is that what you try to achieve? Then you have to make sure that the one containing the DestroyAtom-code is located in your model tree above the atoms that it tries to destroy and create a check if the Atom it tries to destroy is still existing:

Code: Select all

If(
  AtomExists(ciao),
  DestroyAtom(ciao)
)

But as said, I'm still interested about the bigger picture :-)

Cheers,

Harry
Chiara
Posts: 30
Joined: Thursday 20 September, 2012 - 09:40

Re: Closing application

Post by Chiara »

Hello Harry,

in my customized library I need to destroy a table when I destroy a specific atom. The table is stored in a global variable and at the top of the model tree. The atom I manually destroy is at the bottom. In the table atom I have the code that set the global variable to 0 on destruction, and in the other atom the code that destroys the table only if the global variable is set (and the table exists).

You said that the destroying atom needs to be above the table to be destroyed because the closing procedure starts do delete the objects from the bottom of the model tree (using the "last" command), isn'it?

I'm going to try and let you know!

Thanks!
Post Reply