Notifications
Clear all

[Closed] Garbage Collection issue with dotNet Timer

I worked around the problems listed in my last post by embedding a (dotNetMXSValue this) into the tag properties of the dotnet controls so that the events know which instance of the struct contains the calling control. The data I had in the tag property was an integer, so I tossed that into the .imageIndex property. shrug I guess next time I could toss an array into the tag property with all the data I need.

The event handler functions still think they’re being run from the struct typeDef, but they don’t complain if they don’t have to access any of the struct’s local variables, they access them through the tag property’s instance instead.

However…

I’m back to where I was originally with the dotnet eventhandlers getting stripped when I try to build them directly from a max customAttribute rollout. It’s really annoying me:

  1. My dotnet UI, in all it’s new struct glory, is run from the listener. It builds the UI perfectly fine and attaches the eventHandlers as expected.

  2. I have a Custom Attribute rollout with a button, and its pressed() event calls the same function I ran successfully from the listener. It builds the UI but no events stay attached.

  3. Custom Attribute rollout again, but the button builds a global rollout “rkLauncher” into a createDialog, rkLauncher has one button, and that runs the function to build the dotnet UI. This works just as in #1, events are fine.

  4. So I tried doing this: The “rkLauncher” rollout instead of having a button for the user to click has an opened event that launches the dotNet control without user interaction. This works as in #2, the UI builds BUT no events stay attached.

Can you post something that can be run to see these errors first hand. Just strip down you code to only what is needed to produce the error.

Here’s a slight re-work of the script I posted in my original plea for help: http://forums.cgsociety.org/showthread.php?f=98&t=910111

Running this code as-is will create a single point helper with the CA attached to it. Click the button in the CA and the window will open but the events won’t work despite the setLifetimeControl when creating the event handlers.

However just running the create function in listener “rkUI.rkMakeForm()” will create the window and the event handlers will stick.

struct rkUIstruct (
  	rkForm,
  	rkButtons,
  	fn rkui_btnEvent a b =
  	(
  		format "clicked button %
" a.tag
  	),
  	fn rkAddEvents = 
  	(
  		for b in rkButtons do (
  			dotNet.setLifetimeControl b #dotnet
  			dotNet.addEventHandler b "click" rkui_btnEvent 
  		)
  	),
  	fn rkMakeButton t i =
  	(
  		local lbl = (dotNetObject "System.Windows.Forms.Label")
  		lbl.text = t
  		lbl.tag = i
  		lbl.location = (dotNetObject "System.Drawing.Point" (i*20) 10)
  		lbl.foreColor = (dotNetClass "System.Drawing.Color").FromARGB 255 255 255 255
  		lbl.backColor = (dotNetClass "System.Drawing.Color").FromARGB 64 32 32 32
  		local lfont = (dotNetObject "System.Drawing.Font" (dotNetObject "System.Drawing.FontFamily" "Microsoft Sans Serif") 7 (dotNetClass "System.Drawing.FontStyle").regular )
  		lbl.font = lfont
  		lbl.maximumSize = (dotNetObject "System.Drawing.Size" 10 16)
  		lbl.padding = lbl.margin = (dotNetObject "system.windows.forms.padding" 0)
  		lbl
  	),
  	fn rkMakeForm = 
  	(
  		rkButtons = #()
  		rkForm = dotnetobject "MaxCustomControls.Maxform"
  		rkForm.backColor = (dotNetClass "System.Drawing.Color").FromARGB 255 125 125 125
  		rkForm.MinimumSize = dotnetobject "System.Drawing.Size" 200 100
  		rkForm.MaximumSize = dotnetobject "System.Drawing.Size" 200 100
  		for i = 1 to 5 do (
  			local v = (rkMakeButton (i as string) i)
  			append rkbuttons v
  		)
  		rkForm.controls.addRange rkbuttons
  		rkForm.showmodeless()
  		rkAddEvents()
  	)
   )
  
  try (rkUI.window.close()) catch()
  global rkUI = rkUIstruct()
  
  if (rkLauncherCA!=undefined) then (
  	try (custAttributes.deleteDef rkLauncherCA) catch()
  )
  global rkLauncherCA = attributes rkLaunch
  (
  	rollout rklro "launch"
  	(
  		button But1 "open window"
  		on But1 pressed do (
  			rkUI.rkMakeForm()
  		)
  	)
  )
   
   if ($launchHlpr!=undefined) then delete $launchHlpr
   p = point name:"launchHlpr" pos:[0,0,0] box:true wirecolor:(color 255 0 0)
   custAttributes.Add p rkLauncherCA
Page 2 / 2