Errors in glsl code are only caught when set() is used #2268

Closed
SableRaf opened this Issue Dec 16, 2013 · 7 comments

Comments

Projects
None yet
3 participants
@SableRaf

These code snippets will explain the issue better:

try {  
    myShader = loadShader( "bad_shader.glsl" );
    myShader.set("resolution", float(width), float(height));
  } catch (RuntimeException e) {
    println("I see dead shaders...");  
  }
try {  
    myShader = loadShader( "bad_shader.glsl" );
  } catch (RuntimeException e) {
    println("this doesn't print");  
  }

Is it by design that loadShader doesn't catch syntax errors in glsl code?

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Dec 16, 2013

Of course, the errors will also be caught when using shader() or filter(), but for some uses, like livecoding, this might be too late.

Of course, the errors will also be caught when using shader() or filter(), but for some uses, like livecoding, this might be too late.

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Dec 16, 2013

Hmm... actually, simply calling shader() isn't enough to trigger an error on faulty glsl. I can't figure out where the error happens. Failing to call set() in the try{} block will result in the sketch crashing and the error being displayed in the error bar.

Hmm... actually, simply calling shader() isn't enough to trigger an error on faulty glsl. I can't figure out where the error happens. Failing to call set() in the try{} block will result in the sketch crashing and the error being displayed in the error bar.

@ghost ghost assigned codeanticode Dec 18, 2013

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf May 17, 2014

Still trying to figure out that one. Here's a full sketch illustrating the issue:

PShader myShader;

void setup() {
  size(640, 360, P2D);

  try {  
    myShader = loadShader( "bad_shader.glsl" );    
  } 
  catch (RuntimeException e) {
    println("this never prints.");
  }

}


void draw() {

  try {
    shader(myShader);
    //myShader.set("baz",0);
  } 
  catch (RuntimeException e) {
    println("This never prints either.");
  }

  try {
    rect(0, 0, width, height);
  } 
  catch (RuntimeException e) {
    println("By the way, this also doesn't print");
  }

}

The file bad_shader.glsl contains the single word foobar.

This is the output:

java.lang.RuntimeException: java.lang.RuntimeException: Cannot compile fragment shader:
ERROR: 0:1: 'foobar' : syntax error syntax error

See full output: http://pastebin.com/raw.php?i=cbUvjigW

If you change the following

  try {
    shader(myShader);
  } 

to

  try {
    shader(myShader);
    myShader.set("baz",0);
  } 

The output is more like what you'd expect:

This never prints either.
OpenGL error 1282 at bot endDraw(): invalid operation
The shader doesn't have a uniform called "baz"
OpenGL error 1282 at top endDraw(): invalid operation

Where does the java.lang.RuntimeException: Cannot compile fragment shader: happen?

Any ideas as to what is going on?

Still trying to figure out that one. Here's a full sketch illustrating the issue:

PShader myShader;

void setup() {
  size(640, 360, P2D);

  try {  
    myShader = loadShader( "bad_shader.glsl" );    
  } 
  catch (RuntimeException e) {
    println("this never prints.");
  }

}


void draw() {

  try {
    shader(myShader);
    //myShader.set("baz",0);
  } 
  catch (RuntimeException e) {
    println("This never prints either.");
  }

  try {
    rect(0, 0, width, height);
  } 
  catch (RuntimeException e) {
    println("By the way, this also doesn't print");
  }

}

The file bad_shader.glsl contains the single word foobar.

This is the output:

java.lang.RuntimeException: java.lang.RuntimeException: Cannot compile fragment shader:
ERROR: 0:1: 'foobar' : syntax error syntax error

See full output: http://pastebin.com/raw.php?i=cbUvjigW

If you change the following

  try {
    shader(myShader);
  } 

to

  try {
    shader(myShader);
    myShader.set("baz",0);
  } 

The output is more like what you'd expect:

This never prints either.
OpenGL error 1282 at bot endDraw(): invalid operation
The shader doesn't have a uniform called "baz"
OpenGL error 1282 at top endDraw(): invalid operation

Where does the java.lang.RuntimeException: Cannot compile fragment shader: happen?

Any ideas as to what is going on?

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Aug 2, 2014

The issue is still present in 3.0a2.

SableRaf commented Aug 2, 2014

The issue is still present in 3.0a2.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Aug 2, 2014

Member

And it will still be present until the issue has been closed. No need to remind us on each release.

Member

benfry commented Aug 2, 2014

And it will still be present until the issue has been closed. No need to remind us on each release.

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Aug 2, 2014

I was trying to help. No need to be rude.

SableRaf commented Aug 2, 2014

I was trying to help. No need to be rude.

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Jun 6, 2015

Member

Fixed with 5e7703e, compilation errors are consistently thrown when calling shader()

Member

codeanticode commented Jun 6, 2015

Fixed with 5e7703e, compilation errors are consistently thrown when calling shader()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment