[ruby-opengl-devel] Crash in glGetShaderInfoLog

Ronald Pijnacker pijnacker at dse.nl
Thu Apr 5 16:01:06 EDT 2007


> On Thursday 05 April 2007 19:57, Ronald Pijnacker wrote:
> > Hi all,
> >
> > I am experiencing a problem with glGetShaderInfoLog: a crash.
> > I tried debugging through it, but I end up somewhere in the runtime,
> > where I cannot follow what's going on anymore (somewhere in ruby_eval).
> >
> > Platform: windows
> > ruby-opengl version: svn version r173.
> > ruby: ruby 1.8.6 (one-click-installer)
> >
> > Any help would be appreciated.
> Can you post the code (ar at least minimal testcase) ? I'm afraid any 
> functionality from 1.1+ wasn't much tested (i was hoping to do that next 
> week), although i got shader code running without problems.

I stripped it as much as possible.
 
> > Also: I was expecting glGetShaderiv to return a bool when passing
> > GL_COMPILE_STATUS. Instead I got 0, which passes through if ...
> > Would it be feasible to return a boolean type when OpenGL docs specify
> > that GL_TRUE or GL_FALSE is returned?
> That would require adding lots of code for each function that may return 
> GLboolean, and also redefining GL_TRUE/FALSE itself to ruby bool. It would 
> also make the code incompatible with C. I don't think that explicitly writing 
> GL_TRUE/FALSE in conditions is that much of inconvenience :) - assuming 
> GL_TRUE/FALSE to be equivalent to true/false isn't good practice even in C.

It is not so much that I mind typing == GL_TRUE (although I prefer not
to) but I know I'll bump into that every now and then. I'll just have
to try to remember.

	Ronald.
-------------- next part --------------
require 'fox16'; include Fox
require 'gl'; include Gl
require 'glu'; include Glu

$width = 800
$height = 800

VERTEX_SHADER_SOURCE = <<__VERTEX_SHADER_SOURCE__

void main(void)
{
    gl_Position = ftransform();
}

__VERTEX_SHADER_SOURCE__
FRAGMENT_SHADER_SOURCE = <<__FRAGMENT_SHADER_SOURCE__

void main(void)
{
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

__FRAGMENT_SHADER_SOURCE__

class TestWindow < FXMainWindow

    def initialize(app)
        super(app, "Test Application", nil, nil, DECOR_ALL, 0, 0, $width, $height)

        @glvisual = FXGLVisual.new(app, VISUAL_DOUBLEBUFFER)
        @canvas = FXGLCanvas.new(self, @glvisual, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT)

        @canvas.connect(SEL_PAINT, method(:on_paint))
        @canvas.connect(SEL_KEYPRESS, method(:on_keypress))
    end

    def create
        super # Create the window
        show(PLACEMENT_SCREEN) # Make the main window appear
    end

    def setup_shader
        unless @program
            @vertex_shader = glCreateShader(GL_VERTEX_SHADER)
            @fragment_shader = glCreateShader(GL_FRAGMENT_SHADER)
            glShaderSource(@vertex_shader, VERTEX_SHADER_SOURCE)
            glShaderSource(@fragment_shader, FRAGMENT_SHADER_SOURCE)
            glCompileShader(@vertex_shader)
            ok1 = glGetShaderiv(@vertex_shader, GL_COMPILE_STATUS)
            raise unless ok1==1
            puts glGetShaderInfoLog(@vertex_shader)
            glCompileShader(@fragment_shader)
            ok2 = glGetShaderiv(@fragment_shader, GL_COMPILE_STATUS)
            raise unless ok2==1
            puts glGetShaderInfoLog(@fragment_shader)

            @program = glCreateProgram
            glAttachShader(@program, @vertex_shader)
            glAttachShader(@program, @fragment_shader)
            glLinkProgram(@program)
            ok = glGetProgramiv(@program, GL_LINK_STATUS)
            raise unless ok==1
        end

        glUseProgram(@program)
        p glGetError
    end

    def on_keypress(sender, sel, event)
        case event.text
            when "q": exit
        end
    end

    def on_paint(sender, sel, event)
        width, height = @canvas.width, @canvas.height
        @canvas.makeCurrent

        setup_shader

        @canvas.swapBuffers if @glvisual.doubleBuffered?
        glFlush
        @canvas.makeNonCurrent        
    end
end

application = FXApp.new("Test", "Test")
window = TestWindow.new(application)
application.create
application.run


More information about the ruby-opengl-devel mailing list