Skip to content

Commit

Permalink
Avoiding exceptions (console warning instead) when native render mate…
Browse files Browse the repository at this point in the history
…rials are null. Using default shape visual material instead.
  • Loading branch information
nmalg committed Apr 19, 2021
1 parent 5d0d9a0 commit 1ddee99
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Editor/AGXUnityEditor/IO/InputAGXFile.cs
Expand Up @@ -551,10 +551,14 @@ private bool CreateRenderData( Node node, AGXUnity.Collide.Shape shape )
}
}

var materialName = string.IsNullOrEmpty( nativeRenderData.getRenderMaterial().getName() ) ?
var materialName = nativeRenderData.getRenderMaterial() == null ||
string.IsNullOrEmpty( nativeRenderData.getRenderMaterial().getName() ) ?
$"{shape.name}_Visual_Material" :
nativeRenderData.getRenderMaterial().getName();

if ( nativeRenderData.getRenderMaterial() == null )
Debug.LogWarning( "<b>WARNING:</b>".Color( Color.yellow ) +
$" Render material for shape {shape.name} is null - default render material will be used instead." );

// No structural changes from previous read visuals.
if ( shapeVisual != null &&
Expand Down Expand Up @@ -913,6 +917,9 @@ private bool CreateCable( Node node )

private static void RestoreLocalDataFrom( Material thisMaterial, agxCollide.RenderMaterial nativeMaterial )
{
if ( nativeMaterial == null )
return;

if ( nativeMaterial.hasDiffuseColor() ) {
var color = nativeMaterial.getDiffuseColor().ToColor();
color.a = 1.0f - nativeMaterial.getTransparency();
Expand Down Expand Up @@ -944,6 +951,9 @@ private Material MaterialFactory( agxCollide.RenderMaterial nativeMaterial )

private Material GetMaterial( agxCollide.RenderMaterial nativeMaterial )
{
if ( nativeMaterial == null )
return Manager.GetOrCreateShapeVisualDefaultMaterial();

Material material = null;
m_materialLibrary.TryGetValue( nativeMaterial.getHash(), out material );
return material;
Expand All @@ -964,6 +974,9 @@ private Material GetMaterial( agxCollide.RenderMaterial nativeMaterial )
agxCollide.RenderMaterial nativeMaterial,
UnityEngine.Object context )
{
if ( nativeMaterial == null )
return material;

// The user is referencing a material that isn't in our data directory.
// We should not couple this material to our native hash when it could
// result in other instances referencing materials in our directory to
Expand Down

0 comments on commit 1ddee99

Please sign in to comment.