Reputation: 21
I am new to Qt and ROS.
I am working on Qt Creator 4.8.0. I have created a catkin workspace in Qt and a mainwindow
was created.
And I am trying to add QVTKWidget
to the mainwindow
. It was successfully built but when it is run, an error message is displayed.
Code: mainwindow.cpp
vtkWidget = new QVTKWidget;
ui.verticalLayout->addWidget(vtkWidget);
ui.verticalLayout->update();
ren = vtkRenderer::New();
vtkWidget->GetRenderWindow()->AddRenderer(ren);
ren->SetBackground(1.0,0,0);
ren->Render();
Error:realloc(): invalid pointer: 0x00007facb5723820 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7facb37d77e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x85d80)[0x7facb37e5d80]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0x22f)[0x7facb37e48ef]
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN9QListData7reallocEi+0x1f)[0x7facada009cf]
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN9QListData6appendEi+0x81)[0x7facada00aa1]
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0x1d6d78)[0x7facadaccd78]
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_Z21qRegisterResourceDataiPKhS0_S0_+0x2e6)[0x7facadac8b16]
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0x7bcc3)[0x7facad971cc3]
/lib64/ld-linux-x86-64.so.2(+0x106ba)[0x7facb6c5a6ba]
/lib64/ld-linux-x86-64.so.2(+0x107cb)[0x7facb6c5a7cb]
/lib64/ld-linux-x86-64.so.2(+0xc6a)[0x7facb6c4ac6a]
Upvotes: 1
Views: 80
Reputation: 10057
You should check if vtkWidget->GetRenderWindow()
returns a valid pointer, before calling AddRenderer
on it, so instead of
vtkWidget->GetRenderWindow()->AddRenderer(ren);
try
vtkRenderWindow * window = vtkWidget->GetRenderWindow();
if(window != nullptr)
{
window->AddRenderer(ren);
//etc.
Same check should be applied to the vtkRenderer
as well:
ren = vtkRenderer::New();
if(ren != nullptr)
{
//etc.
If you happen to spot some null pointer, see if this post helps.
Upvotes: 1