GLSL着色器的运行时错误:ld.so检测到不一致 [英] Runtime error with GLSL shaders: Inconsistency detected by ld.so

查看:164
本文介绍了GLSL着色器的运行时错误:ld.so检测到不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些OpenGL代码以在窗口中绘制一个小点,但是当我尝试使用自己的着色器时,会收到一条我不理解的错误消息.

I am writing some OpenGL code to draw a small dot in a window, but when I try to use my own shaders, I get an error message which I don't understand.

所以,这是我的主要功能:

So, here's my main function:

int main(int argc, char** argv)
{
    // Initialize some things
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(100, 100);
    glutCreateWindow("OpenGL Test");
    glutDisplayFunc(RenderScene);
    glewInit();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // Make the vertex buffer
    Vector3f vertices[1];
    vertices[0] = Vector3f(0.0f, 0.0f, 0.0f);
    glGenBuffers(1, &vertex_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    // Main GLUT loop
    glutMainLoop();
}

这是我的渲染回调函数:

And here's my rendering callback function:

static void RenderScene()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_POINTS, 0, 1);
    glDisableVertexAttribArray(0);
    glutSwapBuffers();
}

这可以编译并正常运行,按预期在黑色背景上显示一个小白点.

This compiles and runs fine, displaying a small white dot against a black background, as expected.

现在,我想使用自己的着色器,而不是默认的着色器.因此,在主函数中,在glutMainLoop()之前,我加入了以下行:

Now, I want to use my own shaders instead of the default ones. So, in the main function, just before glutMainLoop(), I include the line:

MakeShaderProgram("vertex-shader.glsl");

此函数定义为:

static void MakeShaderProgram(std::string shader_filename)
{
    GLuint program = glCreateProgram();
    GLuint shader = glCreateShader(GL_VERTEX_SHADER);
    const GLchar* ptr_filename = &shader_filename[0];
    const GLchar** ptr_filenames = &ptr_filename;
    int filename_lengths[] = {1};
    glShaderSource(shader, 1, ptr_filenames, &filename_lengths[0]);
    glCompileShader(shader);
    glAttachShader(program, shader);
    glLinkProgram(program);
    glUseProgram(program);
}

最后,与可执行文件位于同一目录中的文件"vertex-shader.glsl"具有以下内容:

Finally, the file "vertex-shader.glsl", which is located in the same directory as the executable, has the following contents:

#version 330

layout (location = 0) in vec3 Position;

void main()
{
    gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0);
}

现在,编译此文件就可以了.但是,在运行它时,出现以下错误:

Now, compiling this is fine. However, on running it, I receive the following error:

Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed!

程序在主功能启动后立即中断.我不知道此错误消息的含义,但这是由于尝试使用自己的着色器而不是默认着色器引起的.

The program breaks right after the main function starts. I have no idea what this error message means, but it is caused by attempting to use my own shaders rather than the default shaders.

有人可以解释出什么问题了吗?

Can somebody explain what is going wrong?

如果相关,这是我的CMakeLists.txt文件:

If it is relevant, here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.1)

set(CMAKE_CXX_FLAGS "-std=c++11")

project(OpenGLTest)

find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLUT REQUIRED)

include_directories(${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})

file(GLOB SRCS *.cpp)

add_executable(${PROJECT_NAME} ${SRCS})

target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLEW_LIBRARY} ${GLUT_LIBRARY})

推荐答案

这是Ubuntu错误.简短的版本是,Ubuntu弄乱了一些OpenGL软件包,并引入了对pthread的依赖,即使在根本不使用pthread的程序中也是如此.一种简单的解决方法是将pthread添加到要链接的库列表中.

This is a Ubuntu bug. The short version is, that Ubuntu messed some up their OpenGL packages and introduced a dependency on pthread, even in programs that are not using pthread at all. The simple workaround solution is to add pthread to the list of libraries to be linked.

如果使用非打包的OpenGL实现(例如AMD/ATI或NVidia专有驱动程序),则会触发该错误.

The bug gets triggered if a non-packaged OpenGL implementation gets used (like the AMD/ATI or NVidia proprietary drivers).

请参见 https://bugs.launchpad .net/ubuntu/+ source/nvidia-graphics-drivers-319/+ bug/1248642

这篇关于GLSL着色器的运行时错误:ld.so检测到不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆