max2027 crashes when using maxscript to display a WPF window

max2027 crashes when using maxscript to display a WPF window

lgedZV4XV
Explorer Explorer
1,336 Views
37 Replies
Message 1 of 38

max2027 crashes when using maxscript to display a WPF window

lgedZV4XV
Explorer
Explorer

In 3dsmax 2027, any WPF window created with maxscript will crash when show it, for example:

(dotnetObject "System.Windows.Window").Show()

 

0 Likes
Accepted solutions (1)
1,337 Views
37 Replies
Replies (37)
Message 21 of 38

denisT.MaxDoctor
Advisor
Advisor

Confirm it again: the only real option is to use ElementHost. I would estimate the chances of success at around 90%.

 

Technically, I don’t see any major difficulties. Windows Forms should work.

0 Likes
Message 22 of 38

spacefrog_
Advisor
Advisor

Just tested against the just released 3ds Max 2027.1 update and sadly IT'S not FIXED !!!


Josef Wienerroither
Software Developer & 3d Artist Hybrid
0 Likes
Message 23 of 38

Mr.Drm
Contributor
Contributor
(
    xamlstring = "
    <UserControl
        xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
        <Grid Margin='10'>
			<TextBlock Text='Hello from WPF'/>
        </Grid>
    </UserControl>
    "
    form = dotnetobject "system.windows.forms.form"
	form.text = "WPF in ElementHost"
	
    elementhost = dotnetobject "system.windows.forms.integration.elementhost"
    elementhost.child = (dotnetclass "system.windows.markup.xamlreader").parse xamlstring
    form.controls.add elementhost
    form.show()
)

I ran this simple script and 3ds Max 2027 crashed just as it did without using ElementHost!
Guys, please fix this issue as soon as possible – my working scripts are now useless!

 

0 Likes
Message 24 of 38

denisT.MaxDoctor
Advisor
Advisor

Nice snippet 👍

try this one:

(
    xamlstring = "
    <UserControl
        xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
        <Grid Margin='10'>
			<TextBlock Text='Hello from WPF'/>
        </Grid>
    </UserControl>
    "
    form = dotnetobject "MaxCustomControls.Maxform"
	form.text = "WPF in ElementHost"
    elementhost = dotnetobject "system.windows.forms.integration.elementhost"
    elementhost.child = (dotnetclass "system.windows.markup.xamlreader").parse xamlstring
    form.controls.add elementhost
    form.Show() 
)


dotnetobject "MaxCustomControls.Maxform"

 

0 Likes
Message 25 of 38

MartinBeh
Advisor
Advisor

@denisT.MaxDoctor wrote:

Nice snippet 👍

try this one


At least for me, this also does not work. Same thing: freeze of UI, no error message, crash to desktop.

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 26 of 38

denisT.MaxDoctor
Advisor
Advisor

Do you like using XAML as your source for WPF? That’s perfectly fine; I just want to narrow the scope a bit...

0 Likes
Message 27 of 38

denisT.MaxDoctor
Advisor
Advisor

I roughly understand how the breakage happens, what exactly Max breaks, and how it happens. I want to start the process so that by the time this breakage occurs, all internal structures are already properly initialized.

 

0 Likes
Message 28 of 38

denisT.MaxDoctor
Advisor
Advisor

Could you please tell me exactly which step causes the freeze and crash?

0 Likes
Message 29 of 38

denisT.MaxDoctor
Advisor
Advisor
 

After crashing the recent snippet, the chances of final success drop dramatically 😄 I guess the problem leaks into the WPF dispatcher afterward.

But even that is not fatal yet… what really matters is that the problem does not sink to the rendering level. If it does, then we’ll probably just have to throw our hands up.

 

0 Likes
Message 30 of 38

MartinBeh
Advisor
Advisor

Well... the line that crashes is 

form.Show()

 

Not sure what else I can tell you?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 31 of 38

Mr.Drm
Contributor
Contributor

Yes, all my scripts have pure XAML UI.

0 Likes
Message 32 of 38

Mr.Drm
Contributor
Contributor

Thanks, but it doesn't work 😞

0 Likes
Message 33 of 38

Mr.Drm
Contributor
Contributor

This is the worst news I've heard in a long time... I hate maxscript UI controls, and rewriting all my tools to use it would be suicide for me...

0 Likes
Message 34 of 38

denisT.MaxDoctor
Advisor
Advisor

I don’t like rollout UI controls either, but for over 25 years they’ve somehow remained the only “correct” option... meanwhile, all my tools from the early 2000s are still alive and working perfectly fine in all versions.

 

 

0 Likes
Message 35 of 38

denisT.MaxDoctor
Advisor
Advisor

@MartinBeh wrote:

Well... the line that crashes is 

form.Show()

 

Not sure what else I can tell you?


one more test (please tell the moment of the crash):

	
(
	xamlstring = @"
	<UserControl
		xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
		xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
		<Grid Margin='10'>
			<TextBlock Text='Hello from WPF'/>
		</Grid>
	</UserControl>
	"

	form = dotnetobject "MaxCustomControls.Maxform"
	form.Text = "WPF in ElementHost"
	elementhost = dotnetobject "System.Windows.Forms.Integration.ElementHost"
	form.controls.Add elementhost

	form.Showmodeless() 
	---form.Close() 
	

	elementhost.Child = (dotnetclass "System.Windows.Markup.XamlReader").parse xamlstring

)

 

(
	try(form.close()) catch()

	form = dotnetobject "MaxCustomControls.Maxform"
	form.Text = "WPF in Form"	

	form.StartPosition = form.StartPosition.Manual
	form.Location = dotnetobject "System.Drawing.Point" 200 100
	form.Size = dotnetobject "System.Drawing.Size" 400 200
	form.BackColor = form.BackColor.Red	
		
	panel1 = dotnetobject "Panel"
	panel1.Dock = panel1.Dock.Fill
	panel1.BackColor = panel1.BackColor.Red

	panel2 = dotnetobject "Panel"
	panel2.Height = 40
	panel2.Dock = panel2.Dock.Top
	panel2.BackColor = panel2.BackColor.Yellow

	ehost = dotnetobject "Integration.ElementHost"
	ehost.Dock = ehost.Dock.Top
	ehost.Width = 100
	ehost.Height = 20

	wpb = dotnetobject "System.Windows.Controls.ProgressBar"
	b = dotnetobject "System.Windows.Media.SolidColorBrush" ((dotnetclass "System.Windows.Media.Color").FromRGB 255 0 0) 
	wpb.Foreground = b
	wpb.Width = 100
	wpb.Height = 20
	wpb.Value = 50
	ehost.Child = wpb

	panel2.Controls.Add ehost
	form.Controls.Add panel2

	form.showmodeless()
)


... and this one:  

0 Likes
Message 36 of 38

Mr.Drm
Contributor
Contributor

first test:

elementhost.Child = (dotnetclass "System.Windows.Markup.XamlReader").parse xamlstring //<--- crash on this line

second test:

form.showmodeless() //<--- crash on this line

 

0 Likes
Message 37 of 38

Mr.Drm
Contributor
Contributor

Well, not all interfaces can be built with MaxScript controls. For example, I have an XALM UI, and the business logic is in MaxScript. Everything worked fine until 3dsmax2027.xamlui.gif

0 Likes
Message 38 of 38

denisT.MaxDoctor
Advisor
Advisor

I don’t mean any unique UI cases. In this situation, anything that works is good enough — WPF, .NET, Qt, whatever.

 

But if you start overcomplicating things just because you want to make the interface fancy, be ready for it to become a problem sooner or later.

0 Likes