Commits

davep committed 063d1be

SH-2700 Fix for random black textures due to texture index out of bounds. Also change shader to show bright pink on index out of bounds and add assertions to help prevent this sort of bug in the future.

  • Participants
  • Parent commits 5cc3867

Comments (0)

Files changed (4)

File indra/llrender/llshadermgr.cpp

 			}
 
 			text[count++] = strdup("\t}\n");
-			text[count++] = strdup("\treturn vec4(0,0,0,0);\n");
+			text[count++] = strdup("\treturn vec4(1,0,1,1);\n");
 			text[count++] = strdup("}\n");
 		}
 		else
 				text[count++] = strdup(if_str.c_str());
 			}
 
-			text[count++] = strdup("\treturn vec4(0,0,0,0);\n");
+			text[count++] = strdup("\treturn vec4(1,0,1,1);\n");
 			text[count++] = strdup("}\n");
 		}			
 	}

File indra/llrender/llvertexbuffer.cpp

 				llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl;
 			}
 		}
+
+		LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+
+		if (shader && shader->mFeatures.mIndexedTextureChannels > 1)
+		{
+			LLStrider<LLVector4a> v;
+			//hack to get non-const reference
+			LLVertexBuffer* vb = (LLVertexBuffer*) this;
+			vb->getVertexStrider(v);
+
+			for (U32 i = start; i < end; i++)
+			{
+				S32 idx = (S32) (v[i][3]+0.25f);
+				if (idx < 0 || idx >= shader->mFeatures.mIndexedTextureChannels)
+				{
+					llerrs << "Bad texture index found in vertex data stream." << llendl;
+				}
+			}
+		}
 	}
 }
 

File indra/newview/llface.cpp

 		while(dst < end);
 
 		F32 index = (F32) (mTextureIndex < 255 ? mTextureIndex : 0);
+
+		llassert(index <= LLGLSLShader::sIndexedTextureChannels-1);
 		F32 *index_dst = (F32*) vertices;
 		F32 *index_end = (F32*) end;
 

File indra/newview/llvovolume.cpp

 		buffer_index = -1;
 	}
 
-	S32 texture_index_channels = gGLManager.mNumTextureImageUnits-1; //always reserve one for shiny for now just for simplicity
+	S32 texture_index_channels = LLGLSLShader::sIndexedTextureChannels-1; //always reserve one for shiny for now just for simplicity
 	
 	if (gGLManager.mGLVersion < 3.1f)
 	{