From 124b5e51dacfa91d3ede6f5cb8dd0b3d561f57a7 Mon Sep 17 00:00:00 2001 From: Nehon Date: Thu, 28 Aug 2014 10:52:35 +0200 Subject: [PATCH] Fix an issue in the ShaderGenerator where it was unable to find the main function in a shader source when there were additional spaces. Also made the error more explicit when the matching fail. --- .../main/java/com/jme3/shader/ShaderGenerator.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java index e26765f77..cf319dd18 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -146,8 +146,9 @@ public abstract class ShaderGenerator { } if (shaderNode.getDefinition().getType() == type) { int index = findShaderIndexFromVersion(shaderNode, type); - String loadedSource = (String) assetManager.loadAsset(new AssetKey(shaderNode.getDefinition().getShadersPath().get(index))); - appendNodeDeclarationAndMain(loadedSource, sourceDeclaration, source, shaderNode, info); + String shaderPath = shaderNode.getDefinition().getShadersPath().get(index); + String loadedSource = (String) assetManager.loadAsset(new AssetKey(shaderPath)); + appendNodeDeclarationAndMain(loadedSource, sourceDeclaration, source, shaderNode, info, shaderPath); } } } @@ -168,10 +169,13 @@ public abstract class ShaderGenerator { * @param shaderNode the shader node. * @param info the ShaderGenerationInfo. */ - protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info) { + protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { if (loadedSource.length() > 1) { loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); - String[] sourceParts = loadedSource.split("void main\\(\\)\\{"); + String[] sourceParts = loadedSource.split("\\s*void\\s*main\\s*\\(\\s*\\)\\s*\\{"); + if(sourceParts.length<2){ + throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); + } generateDeclarativeSection(sourceDeclaration, shaderNode, sourceParts[0], info); generateNodeMainSection(source, shaderNode, sourceParts[1], info); } else {