Modal set to true and dotNet controls causing crash

With this code, see at the very bottom. When the modal property of the dialog is set to true it crashes max and when it's set to false it doesn't.

I believe this is something to do with the .NET buttons and the event handler. But it would be a great help if someone knew how to fix this to get the dialog as a modal one without it crashing.

Having the buttons here in a `FlowLayoutPanel` is required here as the main script I'm writing requires the buttons to get their invisible property turned on or off.

The 3dsMax version I'm using is 2020.

try destroyDialog RollsRoyce catch()
 
rollout RollsRoyce "" width:400 height:90
(
 
  local btnH = 22
 
  dotNetControl panelVisibleFix "FlowLayoutPanel" width:RollsRoyce.width height:btnH --pos:[0,0]
 
  button btn_test "Regular Button" width:(RollsRoyce.width/2) height:btnH
 
  fn dnDrawingColorFromColorMan name = (clr = (colorMan.getColor name) * 255.0 ; (dotNetClass "System.Drawing.Color").fromARGB clr.x clr.y clr.z)
 
  fn makeNETBtn width height text visible:on =
  (
    local btn = dotNetObject "Button"
    btn.Text = text
    btn.Width = width
    btn.Margin = dotNetObject "Padding" 0 0 0 0
    btn.Height = height
    btn.FlatStyle = btn.FlatStyle.System
    btn.Visible = visible
    btn
    )
 
  fn Btn1Pressed_fn = print "Button 1 Pressed..."
  fn Btn2Pressed_fn = print "Button 2 Pressed..."
 
  on RollsRoyce open do
  (
    local btnW = RollsRoyce.width / 2
 
    local btn1 = makeNETBtn btnW btnH ".NET &Button 1" visible:off
    local btn2 = makeNETBtn btnW btnH ".NET Button 2" visible:off
 
    panelVisibleFix.backColor = dnDrawingColorFromColorMan #background
    panelVisibleFix.Controls.AddRange #(btn1, btn2)
    panelVisibleFix.pos = [0,0]
 
    btn1.visible = on
    btn2.visible = on
 
    dotNet.addEventHandler btn1 "Click" Btn1Pressed_fn
    dotNet.addEventHandler btn2 "Click" Btn2Pressed_fn
 
    btn1.focus()
 
    )
  )
createDialog RollsRoyce modal:true -- Setting modal to true crashes Max
-- createDialog RollsRoyce modal:false -- This doesn't crash Max

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

move buttons variables into the rollout definition, maybe it can help
your example doesn't crash on my end
2014 & 2020

3dwannab's picture

.

I've done that. Does it crash on clicking the .NET Button 2?

This does for me but for some reason, .NET Button 1 doesn't crash it.

try destroyDialog RollsRoyce catch()
 
rollout RollsRoyce "" width:400 height:90
(
 
  local btnH = 22
  local btn1
  local btn2
 
  dotNetControl panelVisibleFix "FlowLayoutPanel" width:RollsRoyce.width height:btnH --pos:[0,0]
 
  button btn_test "Regular Button" width:(RollsRoyce.width/2) height:btnH
 
  fn dnDrawingColorFromColorMan name = (clr = (colorMan.getColor name) * 255.0 ; (dotNetClass "System.Drawing.Color").fromARGB clr.x clr.y clr.z)
 
  fn makeNETBtn width height text visible:on =
  (
    local btn = dotNetObject "Button"
    btn.Text = text
    btn.Width = width
    btn.Margin = dotNetObject "Padding" 0 0 0 0
    btn.Height = height
    btn.FlatStyle = btn.FlatStyle.System
    btn.Visible = visible
    btn
    )
 
  fn Btn1Pressed_fn = print "Button 1 Pressed..."
  fn Btn2Pressed_fn = print "Button 2 Pressed..."
 
  on RollsRoyce open do
  (
    local btnW = RollsRoyce.width / 2
 
    btn1 = makeNETBtn btnW btnH ".NET &Button 1" visible:off
    btn2 = makeNETBtn btnW btnH ".NET Button 2" visible:off
 
    panelVisibleFix.backColor = dnDrawingColorFromColorMan #background
    panelVisibleFix.Controls.AddRange #(btn1, btn2)
    panelVisibleFix.pos = [0,0]
 
    btn1.visible = on
    btn2.visible = on
 
    dotNet.addEventHandler btn1 "Click" Btn1Pressed_fn
    dotNet.addEventHandler btn2 "Click" Btn2Pressed_fn
 
    btn1.focus()
 
    )
  )
createDialog RollsRoyce modal:true -- Setting modal to true crashes Max
-- createDialog RollsRoyce modal:false -- This doesn't crash Max
jahman's picture

.

yes, you're right it crashes no matter what I do

3dwannab's picture

..

It's a strange one!! I really need dotNet buttons as objects as I need them to be hidden when required.

Here's a 2013 thread about it but no answer to it. Amazing this has been a bug this long.

https://forums.cgsociety.org/t/strange-crash-with-mixed-dotnet-and-max-b...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.