I can't slove this error "realloc(): invalid pointer"

asked 2020-03-20 06:00:27 -0500

whoamic gravatar image

updated 2020-03-23 02:55:22 -0500

I use Ubuntu 18.04 in linux and c++ , ROS-melodic, Qt Creator 4.5.2 based on Qt 5.9.5.

I achieved my goal to express 3D UI in Qt.

I made my ros-qt-package ( ~/catkin_ws/src

catkin_create_qt_pkg vision_study roscpp)

When I debug this package (rosrun depth_cam depth_cam)

It showed error "realloc(): invalid pointer Aborted (core dumped)"

I never used thing like malloc( ), realloc( )..ect.

So I can't solve this error... PPlease help..me OTL

I offer my qt package.

this is CmakeFILE.

##############################################################################
# CMake
##############################################################################

cmake_minimum_required(VERSION 2.8.0)
project(depth_cam)
#SET(${TARGET}_HEADERS glwidget.h)
#SET(${TARGET}_SOURCES main.cpp glwidget.cpp)
##############################################################################
# Catkin
##############################################################################

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(Qt5 REQUIRED COMPONENTS Core Gui OpenGL)
find_package(catkin REQUIRED COMPONENTS geometry_msgs
                                        qt_build 
                    std_msgs
                    sensor_msgs
                                        roscpp
                    message_generation
                                        roslib
                                        tf)
include_directories(${catkin_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything. 
catkin_package()

##############################################################################
# Qt Environment
##############################################################################

# this comes from qt_build's qt-ros.cmake which is automatically 
# included via the dependency call in package.xml
rosbuild_prepare_qt4(QtCore QtGui Opengl) # Add the appropriate components to the component list here

##############################################################################
# Sections
##############################################################################

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/depth_cam/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

##############################################################################
# Sources
##############################################################################

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

##############################################################################
# Binaries
##############################################################################
add_message_files(FILES msgTutorial.msg)
add_executable(depth_cam ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(depth_cam ${QT_LIBRARIES} ${catkin_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLUT_LIBRARY} -lglut -lGL Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets)
install(TARGETS depth_cam RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

This is main.cpp

#include <QtGui>
#include <QApplication>
#include "../include/depth_cam/main_window.hpp"
#include "geometry_msgs/Point.h"
#include <GL/glut.h>
#include <stdlib.h>


/*****************************************************************************
** Main
*****************************************************************************/
int main(int argc, char **argv) {

  QApplication app(argc, argv);
  depth_cam::MainWindow w(argc,argv);


  w.show();
  app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
  int result = app.exec();

  return result;
}

This is glwidget.hpp file

#ifndef GLWIDGET_HPP
#define GLWIDGET_HPP
#include <QtGui/QMainWindow>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QtOpenGL>
#include <GL/glut.h>

//#include <QGLWidget>
#include <QTimer>
//#include "qgl.h"
#include <QObject>
#include <QtCore/qobject.h>
#include "stdlib.h"
#include <qobject.h>
#include <QtGui>
//#include <GL/glut.h>
#include "qobject.h"
//#include "<depth_cam/>.moc"

class GLWidget : public QGLWidget
{

Q_OBJECT
public:
  explicit GLWidget(QWidget *parent = 0):
    QGLWidget(parent)
  {
    this->R = 1;
    this->wired =false;
    this->ang =0.5;

    connect(&timer,SIGNAL(timeout()),this,SLOT(updateGL()));
   // free(parent);
 //   realloc(parent,100);
    timer.start(16);
  }
  ~GLWidget()
  {}
    void initializeGL()
    {
      glClearColor(0.2,0.2,0.2,1);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHTING);
      glEnable(GL_COLOR_MATERIAL);

    }
    void paintGL()
    {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      //   gluLookAt(0,0,5, 0,0,0,  0,1,0);

      ang += 0.5;

      glTranslatef(x,y,z);
      glRotatef(ang,1,1,1);

      glColor3f(1,0,0);
      glutWireSphere(2,20,20);

    }
    void resizeGL(int w,int h)
    {
      glViewport(0,0, w,h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
    //  gluPerspective(45.0 ...
(more)
edit retag flag offensive close merge delete

Comments

Does the error message tell you which file referenced the pointer?

billy gravatar image billy  ( 2020-03-22 15:45:35 -0500 )edit

I solved this problem It was because of CMAKE file ,,,, LOL When I modified CMAKE file, it worked like magic!!!~~

whoamic gravatar image whoamic  ( 2020-03-23 02:57:58 -0500 )edit