Информация о компьютере:
- NVIDIA Corporation G96M [GeForce 9600M GT]
- Linux Mint 18.2
Я новичок в программировании на C ++, и в течение двух месяцев я писал скрипт для генерации случайных 2D-текстур с помощью этого алгоритма:
http://web.archive.org/web/20080228054410/http://www.davebollinger.com/works/pixelspaceships/
Я использую OpenGL 3 (с GLEW и GLFW 3) для отображения результата, Magick ++ для построения текстур PNG и FastNoise, чтобы результат отличался при каждом запуске программы.
С Valgrind я получил две утечки памяти (и многие другие очень похожие):
==2525== 10 bytes in 1 blocks are still reachable in loss record 11 of 1,389
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x707E489: strdup (strdup.c:42)
==2525== by 0x8026186: ??? (in /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0)
==2525== by 0x8025F4D: _glapi_get_proc_address (in /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0)
==2525== by 0x50D8982: glXGetProcAddress (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x4E88FDC: glewInit (in /usr/lib/x86_64-linux-gnu/libGLEW.so.1.13.0)
==2525== by 0x426809: MyWindow::CreateContext(char*) (MyWindow.cpp:40)
==2525== by 0x4266C7: MyWindow::MyWindow(char*) (MyWindow.cpp:5)
==2525== by 0x428AF5: main (main.cpp:11)
==2525== 24 bytes in 1 blocks are still reachable in loss record 200 of 1,389
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x10956743: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x109FE1DA: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x445C54: _glfwInitGLX (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x441B3F: _glfwPlatformCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x438C14: glfwCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
MyWindow.cpp:
#include "MyWindow.h"
MyWindow::MyWindow(char* argv){
CreateContext(argv);
}
void MyWindow::CreateContext(char* argv){
Magick::InitializeMagick(argv);
glfwInit();
//set OpenGl version
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
//window non resizable
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//get screen size
const GLFWvidmode* screen = glfwGetVideoMode(glfwGetPrimaryMonitor());
m_Width = screen->width;
m_Height = screen->height;
//create window
m_Window = glfwCreateWindow(m_Width, m_Height, "My Window", nullptr, nullptr);
//hide cursor
glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
//Context
glfwMakeContextCurrent(m_Window);
glewExperimental = GL_TRUE;
glewInit();
//Allow transparency for textures
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
MyWindow::~MyWindow(){
Magick::TerminateMagick();
glfwDestroyWindow(m_Window);
glfwTerminate();
}
MyWindow.h:
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#ifndef MyWindow_H_Included
#define MyWindow_H_Included
//Include
#include <GL/glew.h>
#include <GLFW/glfw3.h>
class MyWindow {
private:
GLFWwindow* m_Window;
unsigned int m_Width;
unsigned int m_Height;
void CreateContext(char* argv);
public:
MyWindow(char* argv);
~MyWindow();
};
#endif
Компиляция:
g++ -I./lib/FastNoise -Wall -g -std=c++11 -I./include `Magick++-config --cxxflags --cppflags --ldflags --libs` -lGLEW -lglfw3 -lGL -lsfml-system -lXxf86vm -lXrandr -lpthread -lXi -ldl -lXinerama -lX11 -lXcursor -c -o obj/MyWindow.o src/MyWindow.cpp
Я знаю, что это только "все еще достижимые" утечки памяти, и это не большая проблема, которую я мог бы иметь, но по этой ссылке автор сказал, что "часто разумно" освобождать их:
http://valgrind.org/docs/manual/faq.html#faq.deflost
Я не знаю, что я делаю неправильно в MyWindow.cpp, так что glewInit () и glfwInit () делают эти ошибки. Могут ли они быть сгенерированы этой ошибкой:
==2525== ERROR SUMMARY: 6 errors from 2 contexts (suppressed: 0 from 0)
==2525==
==2525== 1 errors in context 1 of 2:
==2525== Syscall param ioctl(generic) points to uninitialised byte(s)
==2525== at 0x70EFF47: ioctl (syscall-template.S:84)
==2525== by 0x90A3477: drmIoctl (in /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0)
==2525== by 0x90A624E: drmCommandWriteRead (in /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0)
==2525== by 0x11578DA0: nouveau_object_mthd (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x11579535: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== Address 0x102ef182 is 2 bytes inside a block of size 136 alloc'd
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x11578D65: nouveau_object_mthd (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x11579535: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x445C54: _glfwInitGLX (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x441B3F: _glfwPlatformCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== Uninitialised value was created by a heap allocation
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x11578D65: nouveau_object_mthd (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x11579535: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x445C54: _glfwInitGLX (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x441B3F: _glfwPlatformCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525==
==2525== 5 errors in context 2 of 2:
==2525== Syscall param ioctl(generic) points to uninitialised byte(s)
==2525== at 0x70EFF47: ioctl (syscall-template.S:84)
==2525== by 0x90A3477: drmIoctl (in /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0)
==2525== by 0x90A624E: drmCommandWriteRead (in /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0)
==2525== by 0x11578A88: ??? (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x1157951A: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== Address 0x102ef0f2 is 2 bytes inside a block of size 72 alloc'd
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x11578A33: ??? (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x1157951A: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x445C54: _glfwInitGLX (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x441B3F: _glfwPlatformCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== Uninitialised value was created by a heap allocation
==2525== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2525== by 0x11578A33: ??? (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x1157951A: nouveau_device_new (in /usr/lib/x86_64-linux-gnu/libdrm_nouveau.so.2.0.0)
==2525== by 0x109FE120: nouveau_drm_screen_create (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x105654E5: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108C2AC0: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x108BDFDF: ??? (in /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so)
==2525== by 0x5104232: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50DBD03: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x50D7240: glXQueryVersion (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==2525== by 0x445C54: _glfwInitGLX (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
==2525== by 0x441B3F: _glfwPlatformCreateWindow (in /home/pablo/WorkSpacePerso/CppProjet/Infinite_loop_OpenGL/bin/main)
или это что-то еще?
Если вам нужно больше подробностей, вы можете найти результат команды:
"valgrind -v --show-leak-types = all --leak-check = full --track-originins = yes bin / main"
здесь:
https://jumpshare.com/v/gu71bBe0RbDhyxJ8BXg6