PDA

View Full Version : Plugin helper crash on redraw view


lanimal
03-12-2012, 03:53 PM
Hi guy, i'm in front of a strange problem and don't where to search.
Quick explanation:
I made a plugin helper that call init function on a list of objects at file opening
using "on postLoad" event.
Each one of those objects create a when handler for handling controllers visibility
Everything works fine at scne creation but when i reload the file... crash!
Any ideas are welcome.

Here is my code:

------------------------------------------------------------
------------------------------------------------------------
/*
launch init function on each obj contained in visObjs
will try to find a custAttribute containing a "vis_*" parameter
*/
------------------------------------------------------------
plugin Helper visHelper
name:"visHelper"
classID:#(0x2651bdea, 0x204587d4)
category:"Standard"
extends:dummy
(
local lastSize
------------------------------------------------------------
parameters pblock rollout:params
(
size type:#float animatable:true ui:amount default:1.0
visObjs type:#maxObjectTab tabSizeVariable:true
)
------------------------------------------------------------
fn cleanList =
(
goodObjs = for obj in visObjs where obj.node != undefined collect obj
visObjs.count = 0
for i in 1 to goodObjs.count do
( visObjs[i] = goodObjs[i] )
)
fn loadEvent unload:false =
(
cleanList()
if (visObjs.count > 0) then
(
initObjs = #()
-- loop trougth visObjs
for v in 1 to visObjs.count do
(
if ( isValidNode visObjs[v].node ) do
(
curObj = visObjs[v].node
found = false
-- build search array
searchArray = #(curObj)
for m in 1 to curObj.modifiers.count do ( append searchArray curObj.modifiers[m])
-- search for master subAnim
rMod = undefined
curSubAnim = undefined
curSubObjs = undefined
for m in 1 to searchArray.count do
(
curMod = searchArray[m]
try (curSubObjs = curMod.visObjs) catch ()
caCount = custAttributes.count curMod
for sub in 1 to caCount do
(
curCA = custAttributes.get curMod sub
for c in 1 to curCA.numsubs do
(
curControl = (getSubAnim curCA c)
if ( not found ) do
(
if (matchPattern curControl.name pattern:"vis_*") do
(
curSubAnim = curControl
rMod = curMod
found = true
)
)
)
)
)
-- add it to initObjs list if we found a valid visibility custAttribute
if ( curSubAnim != undefined and curSubObjs != undefined ) do
( append initObjs rMod )
-- init those modifiers
if (unload) then
( for m in initObjs do m.uninit() )
else
( for m in initObjs do m.init() )
)
)
)
else
(format "visibilityHelper error: %" "No visibility objects!")
print "loadEvent finished"
)
fn addObj obj =
(
addState = true
for i in 1 to visObjs.count do ( if visObjs[i].node == obj do addState = false )
if addState do
( append visObjs (NodeTransformMonitor node:obj forwardTransformChangeMsgs:false) )
)
------------------------------------------------------------
rollout params "visibility Parameters"
(
Spinner amount "Size:" range:[0, 1e9, 40] align:#right
pickbutton pckAdd "Add object" width:90
on pckAdd picked obj do ( addObj obj )
)
------------------------------------------------------------
on getDisplayMesh do
(
if (meshObj == undefined) do
(
meshObj = createInstance sphere radius:size segs:4
lastSize = size
)
if size != lastSize do
(
meshObj = createInstance sphere radius:size segs:4
lastSize = size
)
meshObj.mesh
)
------------------------------------------------------------
on postLoad do
( loadEvent() )
------------------------------------------------------------
on deleted do
( loadEvent unload:true)
------------------------------------------------------------
tool create
(
on mousePoint click do
(
nodeTM.translation = gridPoint;
#stop
)
)
------------------------------------------------------------
)
------------------------------------------------------------
------------------------------------------------------------
visDef = attributes "visibilityHelperDef"
(
parameters pblock rollout:params
(
vis_IK type:#float animatable:true ui:IKFKSld default:0.0
visObjs type:#maxObjectTab tabSizeVariable:true
self type:#maxObject
)

fn cleanList =
(
goodObjs = for obj in visObjs where obj.node != undefined collect obj
visObjs.count = 0
for i in 1 to goodObjs.count do
( visObjs[i] = goodObjs[i] )
)

fn findVisParam =
(
try ( return (getSubAnim (custAttributes.get self.node.modifiers[1] 1) 1) )
catch ( return undefined )
)

fn visFunc =
(
try
(
stateVis = true
slid = findVisParam()
if (slid.value > 0.9) do stateVis = false
for obj in visObjs do ( try(obj.node.ishidden = not stateVis) catch () )
)
catch
()
)

fn setSelf obj =
( self = NodeTransformMonitor node:obj forwardTransformChangeMsgs:false )

fn init =
(
cleanList()
slid = findVisParam()
if ( slid != undefined ) do
( when parameters slid changes id:#visWhen do ( visFunc() ) )
)

fn uninit =
( deleteAllChangeHandlers id:#visWhen )

fn addVisObj obj =
(
addState = true
for i in 1 to visObjs.count do ( if visObjs[i].node == obj do addState = false )
if addState do
( append visObjs (NodeTransformMonitor node:obj forwardTransformChangeMsgs:false) )
)

rollout params "visibility Parameters"
(
slider IKFKSld "IK" range:[0.0, 1.0, 0.0] align:#left
)
)
------------------------------------------------------------
------------------------------------------------------------
delete $*
VisObj = visHelper()
FKObj = circle radius:2 name:"FK"
IKObj = circle radius:2.5 name:"IK"
addModifier FKObj (EmptyModifier())
custAttributes.add FKObj.modifiers[1] visDef
FKObj.modifiers[1].setSelf FKObj
FKObj.modifiers[1].addVisObj IKObj
addModifier IKObj (EmptyModifier())
custAttributes.add IKObj.modifiers[1] visDef
IKObj.modifiers[1].setSelf IKObj
IKObj.modifiers[1].addVisObj FKObj
-- add controller as vis Objs
VisObj.params.pckAdd.picked FKObj
VisObj.params.pckAdd.picked IKObj
saveMaxFile "C:\\test.max"
loadMaxFile "C:\\test.max"


launch and reload created scene

lanimal
03-12-2012, 04:01 PM
more information:
that's not the when handler who crash max because even when init function doesn't do anything, it also crash.
:surprised

Crash came from the plugin helper itself, oops! :)
Problem solved! :thumbsup:

CGTalk Moderation
03-12-2012, 04:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.