[Closed] NodeEventCallback Failure
Any thoughts?
I have to look at this again today. Been working on other aspects of my tool.
I refactored your code and at some point it just stopped to throw that error.
global PolyFaceExtruder
(
if (globalvars.isglobal #EventCallbackWrapper) do
(
if isstruct (d = globalvars.get #PolyFaceExtruder) do d.EventCallbackWrapper.destroy()
)
PolyFaceExtruderStruct =
(
struct PolyFaceExtruderStruct
(
public
theNodes = #(),
cloneObj = undefined,
EventCallbackStruct =
(
struct EventCallbackStruct
(
public
callbackContainer,
fn doCallbacks event handles =
(
nodes = for handle in handles where isvalidnode (node = GetAnimByHandle handle) collect node
case event of
(
#callbackEnd:
(
PolyFaceExtruder.alignObjectToSO()
)
)
),
fn destroy =
(
callbackContainer = undefined
gc light:on
),
fn create enabled:on =
(
callbackContainer = NodeEventCallback all:doCallbacks enabled:enabled mouseUp:on
),
on create do
(
create()
)
)
),
EventCallbackWrapper = EventCallbackStruct(),
fn cloneTransformObj theSelection = with redraw off
(
with undo off
(
delete theNodes
theNodes = #()
)
if (classof theSelection.baseObject == Editable_Poly) do
(
local theBaseObj = (theSelection.baseObject)
local vertSel = polyop.getVertSelection theBaseObj
local getVertPos = polyop.getVert
if not vertSel.isEmpty do
(
for vert in vertSel do
(
local obj = copy cloneObj
obj.pos = getVertPos theBaseObj vert node:theSelection
obj.isFrozen = true
append theNodes obj
)
)
)
),
fn alignObjectToSO =
(
EventCallbackWrapper.callbackContainer.enabled = false
if SubObjectLevel == 1 do cloneTransformObj selection[1]
redrawViews()
EventCallbackWrapper.callbackContainer.enabled = true
true
),
on create do ()
)
)
PolyFaceExtruder = PolyFaceExtruderStruct()
ok
)
delete objects
p = plane width:15 length:15 widthsegs:8 lengthsegs:8 wirecolor:blue
convertToPoly p
select p
polyop.setVertSelection $.baseObject #{1..($.baseObject.mesh.verts.count)}
update p
t = Teapot()
t.radius = 1.0
setCommandPanelTaskMode #modify
SubObjectLevel = 1
PolyFaceExtruder.cloneObj = t
PolyFaceExtruder.alignObjectToSO()
Thank you!!! I’ll look at this more closely/try it out. :buttrock:
However, I do wonder if it’s soley from this line.
local obj = copy cloneObj
I have a feeling that CloneNodes is the thing causing the issue… I was using it , so I could clone Groups/Hierarchy Setups easier.
But, it seems like you also can’t use Undo with that, which sucks… Which also can cause max crashes if the user undos too much.
But, I might experiment with swapping copy for cloneNodes as a test, in your script, and my previous test as well.
Exceptions appeared even after the change of cloneNodes to a copy, so this was hardly the reason.
Ah ok, thank you! Interesting. Yeah, I will take a look then and see what happens. :banghead::buttrock::applause:
I do need to try to NOT use CloneNodes though if I can… since Clone is much faster, at least, not having the Mod Panel switch back and forth.
The selection change/mod panel change that happens otherwise, from Clonenodes, seems to have it overall take 2-3x longer.
So I was noticing with your new method, if any SO Selection is active, it just keeps looping every frame basically.
So I think it’s deleting/re-cloning the objects extremely quickly, over and over.
I tried to use the method Dennis had again, with the EventCallbackWrapper.destroy(), but that seems to cause the Exception issue.
So I then switched back to your method, but then implemented the fix I have in my current/original version, to stop the loop from happening.
Basically using a bool, set it to True when cloning, and when it tries to jump back in, it only lets it go through if false. So it resets to false, then won’t trigger again until the next SO change/etc.
So I’ll keep testing this, and see if I can’t use Clone instead of CloneNodes as well, since like I said, I think it could maybe end up being 2x faster.
Edit: Actually i just swapped to cloneNodes, and it’s actually like 7x slower in this new code/test. 😮
Well , and I mis-read. There’s alot more calculations going on, but in my original code, it’s actually like currently 20x slower. Than the new method using just Copy.
Well really, the main issue is from cloneNodes exiting the Mod Panel, causing the slowdown I think.
Basically like:
if (PolyFaceExtruder.processing) then
(
PolyFaceExtruder.processing = false
)
else
(
if (not PolyFaceExtruder.processing) do
(
)
)
Particles is an interesting idea…
Well, so, I am using this method, since I do not want to only support geometry. Unless you can do the same with PFlow.
I want to be able to myself, or have the user, align Text/Helpers/anything really. I was looking at that thread yesterday actually. Very cool! But way over my head! haha.
Edit: I’ll snoop around more, but not sure I can use copy either really. Or not without a good bit of work probably, to support Groups/Hierarchy Duping…
Edit 2:
I got all my FNs/Code into that Struct/Code you posted, and it all works.
Edit 3:
Well I took some ideas I implemented in the Struct code you posted, and put it into my Original code.
Now I got modifiers working in there, and got same functionality as Struct version, with no Exception errors.