Crash when trying to assign texture to MaterialInstance

I have a base material and a materialInstance. Each time i try to set a texture (sampling is LinearColor) from within the materialInstance it crashes with the following assert:
Ensure condition failed: Expression [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Editor\MaterialEditor\Private\MaterialInstanceEditor.cpp] [Line: 755]

Hey Simmania -

Can you give us a little more information about this issue, in particular; can you post a screenshot of your Base Material and can you list the exact settings used in your base material texture and in the texture applied to the instance that resulted in the crash?

Let me know -

Eric Ketchum

Hi, making pictures is quite some work but i managed to reproduce the bug with some simple materials.
The bug occurred when converting my base material to a material function.

Here is how to reproduce:

  1. Create a new (base) material add a 2D texture sampler and a (constant) color. Convert the color to a named parameter. Hook them up using a Add expression and put result in emission color. Make the output material a post process material type.
  2. Create a material function. Copy all contents from the material created in 1 to the material function.
  3. Fix the material function by linking the result of the Add to the output color.
  4. Fix the base material by calling a material function with the name of the material function created in 2. Link the result to the emissive color.
  5. Create a material instance with parent set to base material created in 1.
  6. Go the texture in material instance and try to override it with some custom texture.
  7. Crash.

I was hoping that if you create named parameters in material functions that unreal is smart enough to collect them and show them up as overridable parametes in a material instance and that they are still callable from code. Perhaps this is where it goes wrong?

Hey Simmania -

I am still not receiving a crash following your steps. Here is the setup for my Material, Material Function and Material Instance:

Take a look and let me know if you see anything that you did but is not reflected in the images above.

Thank You -

Eric Ketchum

I Eric,

I should have noted that i run the project with VS express edition.
If the project is launched without, it does not crash indeed.

While testing this I noted some other thing as well.

If both MI and MF are opened (2 tabs), and the texture parameter is renamed inside MF. Then apply → save, the name is not visible in MI. When MI is then closed and reopened from content browser, the texture is renamed, but the reference to texture resource/data is lost.

Hey -

I am still not getting a crash using a C++ Compiled project either. Can you reproduce the crash using just the C++ Basic Code project with no starter content?

The reason that you are losing the association in the MI is you have renamed the variable and thus the originally variable does not save the texture independent of that variable. I am going to enter this in as a feature request though as it would be handy to have this function like a Get Set function when renaming.

Let me know about the reproduction in the Basic Code Project -

Eric Ketchum

I tested with a Basic code project without starter content.
I imported a non-power of 2 texture. It complained about not being able to mipmap and streaming. I proceeded.
Tried to replace the texture, and crash.
Then I tried power of 2 and square texture, no complaints, still crash.

Ensure condition failed: Expression [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Editor\MaterialEditor\Private\MaterialInstanceEditor.cpp] [Line: 755]

Hi Eric, I checked the source of Unreal and i noticed the following:

I think the function call (line 752):
UMaterialExpressionTextureSampleParameter* Expression = BaseMaterial->FindExpressionByGUID( TextureParameterValue->ExpressionId );

Always returns NULL.
So, when not starting with visual studio, the check at line 755 is silently ignored.
How do I know?

If for example, in the material function a color texture is used, but replaced by the material instance with a normal map, according to line: 780. A warning (ShadowedString) should be drawn if i am not mistaken…
This is not the case. Which isnt, if the function returns NULL and the check(…) call is ignored.

Hey -

Can you upload a copy of the Name of the Project that you tested when you crashed and your Machine ID number which should both pop up in the Crash Reporter?

Thank You

Eric Ketchum

Hi, it crashes in visual studio. In such case there is no way of just stop running from visual studio and so, no editor window with MachineID or any other info is shown.
I tried uploading .dmp files but upload on this website often fails. I ll try later.

Try zipping the dmp files before uploading them that sometimes help uploading them to the website.

Already tried and renamed extension to unknown… but ill try again now.
I just can get to upload.
It either says: No such upload OR file type is invalid. Tried multiple extensions, without extension… Tried faking extenion to .txt or .png/.jpg. None of them work.

http://we.tl/dRSa9OD468

change extension of file to .7z then unzip with 7z or something can.

Hey simmania -

I was able to reproduce your issue; Visual Studio gave me a breakpoint but when I continued a few times past the breakpoint I was able to successful re-texture the Material Instance and continue working. Is this the behavior you are also seeing? Regardless I have entered a bug report and our engineers are investigating a fix.

Thank You

Eric Ketchum

Well, i cannot continue running in VS. However, if you can, then i would expect no error would occur. The same as in editor as the ‘check’/assert is then ignored.