Skip to content

Commit

Permalink
UPBGE: Fix NULL returned by GetMeshMaterial.
Browse files Browse the repository at this point in the history
GetMeshMaterial was based on blender material index in a previous commit. but this function is used in loop of NumMaterial() iterations.
To solve this the GetMeshMaterial was reset as original and only GetMaterialId (now renamed GetBlenderMaterialId) is still based on blender
material index.
  • Loading branch information
panzergame committed Dec 16, 2015
1 parent 7b8e9cc commit 6fe25a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions source/gameengine/Rasterizer/RAS_MeshObject.cpp
Expand Up @@ -141,6 +141,7 @@ void RAS_MeshObject::UpdateAabb()
unsigned int nmat = NumMaterials();
for (unsigned int imat = 0; imat < nmat; ++imat) {
RAS_MeshMaterial *mmat = GetMeshMaterial(imat);

RAS_MeshSlot *slot = mmat->m_baseslot;
if (!slot)
continue;
Expand Down Expand Up @@ -196,13 +197,12 @@ const STR_String& RAS_MeshObject::GetMaterialName(unsigned int matid)

RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterial(unsigned int matid)
{
for(std::list<RAS_MeshMaterial>::iterator it = m_materials.begin();
it != m_materials.end();
++it)
{
if (it->m_index == matid) {
return &*it;
if ((m_materials.empty() == false) && (matid < m_materials.size())) {
list<RAS_MeshMaterial>::iterator it = m_materials.begin();
while (matid--) {
++it;
}
return &*it;
}

return NULL;
Expand Down Expand Up @@ -261,7 +261,7 @@ RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterial(RAS_IPolyMaterial *mat)
return NULL;
}

int RAS_MeshObject::GetMaterialId(RAS_IPolyMaterial *mat)
int RAS_MeshObject::GetBlenderMaterialId(RAS_IPolyMaterial *mat)
{
list<RAS_MeshMaterial>::iterator mit;

Expand Down
3 changes: 2 additions & 1 deletion source/gameengine/Rasterizer/RAS_MeshObject.h
Expand Up @@ -90,7 +90,8 @@ class RAS_MeshObject

RAS_MeshMaterial *GetMeshMaterial(unsigned int matid);
RAS_MeshMaterial *GetMeshMaterial(RAS_IPolyMaterial *mat);
int GetMaterialId(RAS_IPolyMaterial *mat);
/// Return the material position in the mesh, like in blender.
int GetBlenderMaterialId(RAS_IPolyMaterial *mat);

list<RAS_MeshMaterial>::iterator GetFirstMaterial();
list<RAS_MeshMaterial>::iterator GetLastMaterial();
Expand Down
Expand Up @@ -836,7 +836,7 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(class RAS_MeshSlot &ms)
if (current_polymat->GetFlag() & RAS_BLENDERGLSL) {
// GetMaterialIndex return the original mface material index,
// increment by 1 to match what derived mesh is doing
current_blmat_nr = current_mesh->GetMaterialId(current_bucket->GetPolyMaterial()) + 1;
current_blmat_nr = current_mesh->GetBlenderMaterialId(current_bucket->GetPolyMaterial()) + 1;
// For GLSL we need to retrieve the GPU material attribute
Material* blmat = current_polymat->GetBlenderMaterial();
Scene* blscene = current_polymat->GetBlenderScene();
Expand All @@ -850,7 +850,7 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(class RAS_MeshSlot &ms)
GPU_set_material_alpha_blend(current_blend_mode);
} else {
//ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol);
current_blmat_nr = current_mesh->GetMaterialId(current_bucket->GetPolyMaterial());
current_blmat_nr = current_mesh->GetBlenderMaterialId(current_bucket->GetPolyMaterial());
current_image = current_polymat->GetBlenderImage();
ms.m_pDerivedMesh->drawFacesTex(ms.m_pDerivedMesh, CheckTexDM, NULL, NULL, DM_DRAW_USE_ACTIVE_UV);
}
Expand Down

0 comments on commit 6fe25a0

Please sign in to comment.