Notifications
Clear all

[Closed] with undo "name" on – gc error

Hello.
I’m trying to debug my 3.8k strings code in max2017 because of “garbage collect error” (2013,2016,2018 are okay) and I found a really strange thing.

This code will generate gc error in max2017 but not in other versions, it was checked by 3 different users with the same result (error).


(
   fn test = with undo "undo test" on (
      box()
      gc light:on
   )
   test()
   gc light:on
)

But this code doesn’t generate error


(
   fn test = (
      box()
      gc light:on
   )
   test()
   gc light:on
)

Both of them will add undo record, but first one will name it. I know the code looks silly, why I need gc inside function and then do gc again. This is just an example to get error.
In my script there are many functions with named undo records. I tried to remove all “gc light:on” from functions and still had garbage collect errors after some operations.

Errors gone only when I removed all “with undo on” and that’s all…
Am I doing something wrong?

UPD.
This method works fine.


(
   fn test = (
      undo "undo test" on (
         box()
      )
      gc light:on
   )
   test()
   gc light:on
)

UPD 2.
One more test. This code generates gc error only in 2017. GC now is not even inside function. If I remove undo label (“undo record”) then no error.


(
   fn createInsaneArray = (
      local verts = for v=1 to 85000 collect #()
   )
   fn testFn = undo "undo record" on (
      createInsaneArray()
      box()
   )
   
   for i=1 to 2 do testFn()
   gc light:on
)

I’m still interested why it was okay in 2016 and 2018, but not in 2017.
Forgot to mention that heapsize in all versions is 15MB. If I increase heapsize to 512MB then I need to run this testFn not 2 but 200 times to get gc error. Looks like a bug in 2017.

2 Replies

in general the using of the undo context with a function definition is not a good practice.
usually undo context has to be used with ui control events. (for example when a button is pressed)

there are many reasons for not using this context (as well as other: redraw, animate, etc.) with a function.
for example:

not every call off this function has to be undoable

in different situations the “accept string” might be different:


fn deletenodes nodes =  (delete nodes)  
on delete_cameras_bt pressed do undo "Delete Cameras" on deletenodes cameras
on delete_helpers_bt pressed do undo "Delete Helpers" on deletenodes helpers

several functions might be combined under one undo

undo might be canceled for any reason

etc…

Thanks for an explanation, Denis.
Actually I fixed my script by using local undo scope inside functions and now it’s better than before. And no errors.
Now I’m just curious why adding “name” to undo record generates GC error in some situations and only in max2017. Nobody interested in this outdated 3dsmax? I don’t use it, but some users of my script do.

GC error only in max 2017.


(
   fn createInsaneArray = local verts = for v=1 to 85000 collect #()
   fn testFn = box()

   createInsaneArray()
   undo "undo record" on (
      createInsaneArray()
      testFn()
   )
   gc light:on
)

No errors. Only one change – no undo record name.


(
   fn createInsaneArray = local verts = for v=1 to 85000 collect #()
   fn testFn = box()

   createInsaneArray()
   undo on (
      createInsaneArray()
      testFn()
   )
   gc light:on
)