[vtkusers] vtkRenderWindow.Render() crashes when OpenFOAM functions have been called before

Mirko Ahrens mirkoahr at gmail.com
Tue Apr 28 10:36:00 EDT 2015


Hello,
I am trying to combine VTK6.2 with OpenFOAM (www.openfoam.com).
Unfortunately, the simplest VTK examples crash when I am calling OpenFOAM
functions before. I know, it is difficult for you to judge what happens in
these functions, but maybe you have some hints what to search for, or maybe
some of you are familiar with OpenFOAM. The gdb stacktrace doesn't show
useful information although VTK6.2 and OpenFOAM are compiled with debug
flags. I didn't have such problems with VTK5.8.

I attach below the code of Examples/Tutorial/Step5/Cxx, which is only
modified in 2 lines, and the CMakeLists.txt which includes the additional
settings for OpenFOAM 2.3.1.

The output from running the modified example is:
$ ./Cone5
/*---------------------------------------------------------------------------*\
| =========
|                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD
Toolbox           |
|  \\    /   O peration     | Version:
2.3.1                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org
|
|    \\/     M anipulation
|                                                 |
\*---------------------------------------------------------------------------*/
Build  : 2.3.1-bcfaaa7b8660
Exec   : ./Cone5
Date   : Apr 28 2015
Time   : 14:24:08
Host   : "ip-10-230-129-53"
PID    : 13462
Case   : /home/ubuntu/Tutorial/Step5/Cxx
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using
timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* //
Floating point exception (core dumped)
--- End of output ---

--- CMakeLists.txt ---
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
if(POLICY CMP0025)
  cmake_policy(SET CMP0025 NEW) # CMake 3.0
endif()
if(POLICY CMP0053)
  cmake_policy(SET CMP0053 NEW) # CMake 3.1
endif()

PROJECT (Step5)

find_package(VTK COMPONENTS
  vtkCommonCore
  vtkFiltersSources
  vtkInteractionStyle
  vtkRenderingOpenGL
)
include(${VTK_USE_FILE})
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -m64 -Dlinux64 -DWM_DP -DNoRepository
-Xlinker --add-needed")

include_directories($ENV{FOAM_SRC}/finiteVolume/lnInclude
$ENV{FOAM_SRC}/OpenFOAM/lnInclude $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude)

add_executable(Cone5 MACOSX_BUNDLE Cone5.cxx)
target_link_libraries(Cone5 ${VTK_LIBRARIES}
$ENV{FOAM_LIBBIN}/libfiniteVolume.so $ENV{FOAM_LIBBIN}/libOpenFOAM.so
$ENV{FOAM_LIBBIN}/libmeshTools.so)
--- End of CMakeLists.txt ---

--- modified Cone5.cxx: ---
#include <fvCFD.H> //added for OpenFOAM
// First include the required header files for the VTK classes we are using.
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkInteractorStyleTrackballCamera.h"

int main(int argc, char **argv)
{
  Foam::argList args(argc, argv); //initializes OpenFOAM

  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInputConnection( cone->GetOutputPort() );
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );

  //renWin->Render(); //Using this call instead of the remaining code
  //causes a crash, too.

  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  vtkInteractorStyleTrackballCamera *style =
    vtkInteractorStyleTrackballCamera::New();
  iren->SetInteractorStyle(style);
  iren->Initialize();
  iren->Start();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  style->Delete();
  return 0;
}
--- End of Cone5.cxx ---

Every input is welcome!
Mirko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150428/fd52494e/attachment.html>


More information about the vtkusers mailing list