question

G. Moser avatar image
0 Likes"
G. Moser asked Matthew Gillespie commented

The OnDestroy code is executed two times when an object is deleted

TestOnDestroy.fsmHello,

I am currently working on an user library and I needed a script to be executed when an object of my library is deleted. Therefore I have added an OnDestroy node in the behaviour/eventfunctions node. Although it works fine in the 23.1 version, in latest version (23.2.1) it gives me an error. This error occurs because the code is executed two times instead of once and the second time it can not access the nodes because the object related is already destroyed. I make some tests to confirm that behaviour by just adding a message in OnDestroy and it was executed two times everytime I deleted an instance of the object. I attached a small model showing that exemple. I am pretty sure it is not a normal behaviour.

Regards!

TestOnDestroy.fsm

FlexSim 23.2.1
user libraryeventfunctionsondestroy
testondestroy.fsm (35.8 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Matthew Gillespie commented

This appears to be caused by a bug-fix with the undo system, where OnDestroy wasn't being called when redoing a delete operation after an undo.

I'll add a case to the dev list to look into fixing this.

In the meantime, I suggest adding some conditional logic to your code to make it robust enough to work when called twice and still work once this gets fixed.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·
@G. Moser This issue is fixed in 24.0.0 released yesterday.
0 Likes 0 ·