Bug with setting a dialog to modal and dotNet button (Causes 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.

If you press the .NET Button 1 it’s ok but not .NET Button 2. That causes an immediate hang that requires Max to be closed.

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 visible property turned on or off.

The 3dsMax version I’m using is 2020.

I wonder if there has been a workaround found for this since?

Here’s a 2013 closed thread about the same.

try destroyDialog RollsRoyce catch()

rollout RollsRoyce "" width:400 height:90

  local btnH = 22

  dotNetControl panelVisibleFix "FlowLayoutPanel" width:RollsRoyce.width height:btnH

  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 fun 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
    dotNet.addEventHandler btn "Click" fun

  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" Btn1Pressed_fn visible:off
    btn2 = makeNETBtn btnW btnH ".NET Button 2" Btn2Pressed_fn visible:off

    panelVisibleFix.backColor = dnDrawingColorFromColorMan #background
    panelVisibleFix.Controls.AddRange #(btn1, btn2)
    panelVisibleFix.pos = [0,0]

    btn1.visible = on
    btn2.visible = on


createDialog RollsRoyce modal:true -- Setting modal to true crashes Max
-- createDialog RollsRoyce modal:false -- This doesn't crash Max