Program: 160527
Project: 160527
Buggy source:
public void generateGeometry(long uoid,PluginManager pluginManager,DatabaseSession databaseSession,IfcModelInterface model,int pid,int rid,Revision revision,boolean store,GeometryCache geometryCache) throws BimserverDatabaseException, GeometryGeneratingException {
  if (geometryCache != null && !geometryCache.isEmpty()) {
    returnCachedData(model,geometryCache,databaseSession,pid,rid);
    return;
  }
  SerializerPlugin serializerPlugin=(SerializerPlugin)pluginManager.getPlugin("String_Node_Str",true);
  Serializer serializer=serializerPlugin.createSerializer(new PluginConfiguration());
  try {
    model.generateMinimalExpressIds();
    serializer.init(model,null,pluginManager,null,false);
    ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
    serializer.writeToOutputStream(outputStream);
    User user=(User)databaseSession.get(uoid,Query.getDefault());
    UserSettings userSettings=user.getUserSettings();
    RenderEnginePluginConfiguration defaultRenderEngine=userSettings.getDefaultRenderEngine();
    if (defaultRenderEngine != null) {
      RenderEnginePlugin renderEnginePlugin=pluginManager.getRenderEngine(defaultRenderEngine.getPluginDescriptor().getPluginClassName(),true);
      try {
        RenderEngine renderEngine=renderEnginePlugin.createRenderEngine(new PluginConfiguration());
        renderEngine.init();
        try {
          RenderEngineModel renderEngineModel=renderEngine.openModel(new ByteArrayInputStream(outputStream.toByteArray()),outputStream.size());
          RenderEngineSettings settings=new RenderEngineSettings();
          settings.setPrecision(Precision.SINGLE);
          settings.setIndexFormat(IndexFormat.AUTO_DETECT);
          settings.setGenerateNormals(true);
          settings.setGenerateTriangles(true);
          settings.setGenerateWireFrame(false);
          renderEngineModel.setSettings(settings);
          try {
            RenderEngineSurfaceProperties initializeModelling=renderEngineModel.initializeModelling();
            RenderEngineGeometry renderEngineGeometry=renderEngineModel.finalizeModelling(initializeModelling);
            List<IfcProduct> products=model.getAllWithSubTypes(IfcProduct.class);
            GeometrySimplifier geometrySimplifier=new GeometrySimplifier();
            for (            IfcProduct ifcProduct : products) {
              RenderEngineInstance renderEngineInstance=renderEngineModel.getInstanceFromExpressId(ifcProduct.getExpressId());
              RenderEngineInstanceVisualisationProperties visualisationProperties=renderEngineInstance.getVisualisationProperties();
              if (visualisationProperties.getIndices() != null && visualisationProperties.getIndices().length > 0) {
                GeometryInfo geometryInfo=null;
                if (store) {
                  geometryInfo=databaseSession.create(Ifc2x3tc1Package.eINSTANCE.getGeometryInfo(),pid,rid);
                }
 else {
                  geometryInfo=Ifc2x3tc1Factory.eINSTANCE.createGeometryInfo();
                }
                geometryInfo.setMinBounds(createVector3f(Float.POSITIVE_INFINITY,databaseSession,store,pid,rid));
                geometryInfo.setMaxBounds(createVector3f(Float.NEGATIVE_INFINITY,databaseSession,store,pid,rid));
                GeometryData geometryData=null;
                if (store) {
                  geometryData=databaseSession.create(Ifc2x3tc1Package.eINSTANCE.getGeometryData(),pid,rid);
                }
 else {
                  geometryData=Ifc2x3tc1Factory.eINSTANCE.createGeometryData();
                }
                geometryData.setIndices(intArrayToByteArray(visualisationProperties.getIndices()));
                geometryData.setVertices(floatArrayToByteArray(visualisationProperties.getVertices()));
                geometryData.setMaterialIndices(intArrayToByteArray(visualisationProperties.getMaterialIndices()));
                geometryData.setNormals(floatArrayToByteArray(visualisationProperties.getNormals()));
                float[] vertex_colors=new float[visualisationProperties.getVertices().length / 3 * 4];
                for (int i=0; i < visualisationProperties.getMaterialIndices().length; ++i) {
                  int c=visualisationProperties.getMaterialIndices()[i];
                  for (int j=0; j < 3; ++j) {
                    int k=visualisationProperties.getIndices()[i * 3 + j];
                    if (c > -1) {
                      for (int l=0; l < 4; ++l) {
                        vertex_colors[4 * k + l]=visualisationProperties.getMaterials()[4 * c + l];
                      }
                    }
 else {
                      vertex_colors[4 * k]=0;
                      vertex_colors[4 * k + 1]=1;
                      vertex_colors[4 * k + 2]=0;
                      vertex_colors[4 * k + 3]=1;
                    }
                  }
                }
                geometryData.setMaterials(floatArrayToByteArray(vertex_colors));
                for (int i=0; i < visualisationProperties.getIndices().length; i++) {
                  processExtends(geometryInfo,visualisationProperties.getVertices(),visualisationProperties.getIndices()[i] * 3);
                }
                geometryInfo.setData(geometryData);
                float[] tranformationMatrix=new float[16];
                if (renderEngineInstance.getTransformationMatrix() != null) {
                  tranformationMatrix=renderEngineInstance.getTransformationMatrix();
                  tranformationMatrix=Matrix.changeOrientation(tranformationMatrix);
                }
 else {
                  Matrix.setIdentityM(tranformationMatrix,0);
                }
                setTransformationMatrix(geometryInfo,tranformationMatrix);
                if (bimServer.getServerSettingsCache().getServerSettings().isReuseGeometry()) {
                  geometrySimplifier.add(ifcProduct,geometryData);
                }
                ifcProduct.setGeometry(geometryInfo);
                if (store) {
                  databaseSession.store(ifcProduct,pid,rid);
                }
              }
            }
            if (bimServer.getServerSettingsCache().getServerSettings().isReuseGeometry()) {
              for (              IfcProduct ifcProduct : products) {
                if (ifcProduct.getGeometry() != null && ifcProduct.getGeometry().getData() != null) {
                  Set<GeometryData> matchingGeometryDatas=geometrySimplifier.getMatchingGeometry(ifcProduct,ifcProduct.getGeometry().getData());
                  for (                  GeometryData matchingGeometryData : matchingGeometryDatas) {
                    if (reuseGeometry(ifcProduct,ifcProduct.getGeometry(),ifcProduct.getGeometry().getData(),matchingGeometryData)) {
                      break;
                    }
                  }
                }
              }
            }
          }
  finally {
            renderEngineModel.close();
          }
        }
  finally {
          renderEngine.close();
        }
      }
 catch (      RenderEngineException e) {
        LOGGER.error("String_Node_Str",e);
      }
    }
  }
 catch (  Exception e) {
    LOGGER.error("String_Node_Str",e);
    throw new GeometryGeneratingException(e);
  }
}

Fixed version (ground truth):
public void generateGeometry(long uoid,PluginManager pluginManager,DatabaseSession databaseSession,IfcModelInterface model,int pid,int rid,Revision revision,boolean store,GeometryCache geometryCache) throws BimserverDatabaseException, GeometryGeneratingException {
  if (geometryCache != null && !geometryCache.isEmpty()) {
    returnCachedData(model,geometryCache,databaseSession,pid,rid);
    return;
  }
  SerializerPlugin serializerPlugin=(SerializerPlugin)pluginManager.getPlugin("String_Node_Str",true);
  Serializer serializer=serializerPlugin.createSerializer(new PluginConfiguration());
  try {
    model.generateMinimalExpressIds();
    serializer.init(model,null,pluginManager,null,false);
    ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
    serializer.writeToOutputStream(outputStream);
    User user=(User)databaseSession.get(uoid,Query.getDefault());
    UserSettings userSettings=user.getUserSettings();
    RenderEnginePluginConfiguration defaultRenderEngine=userSettings.getDefaultRenderEngine();
    if (defaultRenderEngine != null) {
      RenderEnginePlugin renderEnginePlugin=pluginManager.getRenderEngine(defaultRenderEngine.getPluginDescriptor().getPluginClassName(),true);
      try {
        RenderEngine renderEngine=renderEnginePlugin.createRenderEngine(new PluginConfiguration());
        renderEngine.init();
        try {
          RenderEngineModel renderEngineModel=renderEngine.openModel(new ByteArrayInputStream(outputStream.toByteArray()),outputStream.size());
          RenderEngineSettings settings=new RenderEngineSettings();
          settings.setPrecision(Precision.SINGLE);
          settings.setIndexFormat(IndexFormat.AUTO_DETECT);
          settings.setGenerateNormals(true);
          settings.setGenerateTriangles(true);
          settings.setGenerateWireFrame(false);
          renderEngineModel.setSettings(settings);
          try {
            RenderEngineSurfaceProperties initializeModelling=renderEngineModel.initializeModelling();
            RenderEngineGeometry renderEngineGeometry=renderEngineModel.finalizeModelling(initializeModelling);
            List<IfcProduct> products=model.getAllWithSubTypes(IfcProduct.class);
            GeometrySimplifier geometrySimplifier=new GeometrySimplifier();
            for (            IfcProduct ifcProduct : products) {
              RenderEngineInstance renderEngineInstance=renderEngineModel.getInstanceFromExpressId(ifcProduct.getExpressId());
              RenderEngineInstanceVisualisationProperties visualisationProperties=renderEngineInstance.getVisualisationProperties();
              if (visualisationProperties.getIndices() != null && visualisationProperties.getIndices().length > 0) {
                GeometryInfo geometryInfo=null;
                if (store) {
                  geometryInfo=databaseSession.create(Ifc2x3tc1Package.eINSTANCE.getGeometryInfo(),pid,rid);
                }
 else {
                  geometryInfo=Ifc2x3tc1Factory.eINSTANCE.createGeometryInfo();
                }
                geometryInfo.setMinBounds(createVector3f(Float.POSITIVE_INFINITY,databaseSession,store,pid,rid));
                geometryInfo.setMaxBounds(createVector3f(Float.NEGATIVE_INFINITY,databaseSession,store,pid,rid));
                GeometryData geometryData=null;
                if (store) {
                  geometryData=databaseSession.create(Ifc2x3tc1Package.eINSTANCE.getGeometryData(),pid,rid);
                }
 else {
                  geometryData=Ifc2x3tc1Factory.eINSTANCE.createGeometryData();
                }
                geometryData.setIndices(intArrayToByteArray(visualisationProperties.getIndices()));
                geometryData.setVertices(floatArrayToByteArray(visualisationProperties.getVertices()));
                geometryData.setMaterialIndices(intArrayToByteArray(visualisationProperties.getMaterialIndices()));
                geometryData.setNormals(floatArrayToByteArray(visualisationProperties.getNormals()));
                if (visualisationProperties.getMaterialIndices() != null) {
                  float[] vertex_colors=new float[visualisationProperties.getVertices().length / 3 * 4];
                  for (int i=0; i < visualisationProperties.getMaterialIndices().length; ++i) {
                    int c=visualisationProperties.getMaterialIndices()[i];
                    for (int j=0; j < 3; ++j) {
                      int k=visualisationProperties.getIndices()[i * 3 + j];
                      if (c > -1) {
                        for (int l=0; l < 4; ++l) {
                          vertex_colors[4 * k + l]=visualisationProperties.getMaterials()[4 * c + l];
                        }
                      }
 else {
                        vertex_colors[4 * k]=0;
                        vertex_colors[4 * k + 1]=1;
                        vertex_colors[4 * k + 2]=0;
                        vertex_colors[4 * k + 3]=1;
                      }
                    }
                  }
                  geometryData.setMaterials(floatArrayToByteArray(vertex_colors));
                }
                for (int i=0; i < visualisationProperties.getIndices().length; i++) {
                  processExtends(geometryInfo,visualisationProperties.getVertices(),visualisationProperties.getIndices()[i] * 3);
                }
                geometryInfo.setData(geometryData);
                float[] tranformationMatrix=new float[16];
                if (renderEngineInstance.getTransformationMatrix() != null) {
                  tranformationMatrix=renderEngineInstance.getTransformationMatrix();
                  tranformationMatrix=Matrix.changeOrientation(tranformationMatrix);
                }
 else {
                  Matrix.setIdentityM(tranformationMatrix,0);
                }
                setTransformationMatrix(geometryInfo,tranformationMatrix);
                if (bimServer.getServerSettingsCache().getServerSettings().isReuseGeometry()) {
                  geometrySimplifier.add(ifcProduct,geometryData);
                }
                ifcProduct.setGeometry(geometryInfo);
                if (store) {
                  databaseSession.store(ifcProduct,pid,rid);
                }
              }
            }
            if (bimServer.getServerSettingsCache().getServerSettings().isReuseGeometry()) {
              for (              IfcProduct ifcProduct : products) {
                if (ifcProduct.getGeometry() != null && ifcProduct.getGeometry().getData() != null) {
                  Set<GeometryData> matchingGeometryDatas=geometrySimplifier.getMatchingGeometry(ifcProduct,ifcProduct.getGeometry().getData());
                  for (                  GeometryData matchingGeometryData : matchingGeometryDatas) {
                    if (reuseGeometry(ifcProduct,ifcProduct.getGeometry(),ifcProduct.getGeometry().getData(),matchingGeometryData)) {
                      break;
                    }
                  }
                }
              }
            }
          }
  finally {
            renderEngineModel.close();
          }
        }
  finally {
          renderEngine.close();
        }
      }
 catch (      RenderEngineException e) {
        LOGGER.error("String_Node_Str",e);
      }
    }
  }
 catch (  Exception e) {
    LOGGER.error("String_Node_Str",e);
    throw new GeometryGeneratingException(e);
  }
}