1

I am trying to render a OpenCascade shape using VTK and while setting the Input Connection to Mapper in VTK I am getting vector subscript out of bounds error. However, this error is only happening in debug mode and not in Release mode. The assertion is triggering in the file vtkCommonExecutionModel-9.0d.dll. The code is as follows:

#include <BRepPrimAPI_MakeBox.hxx>
#include <IVtkTools_ShapeDataSource.hxx>

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include<vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkAutoInit.h>
#include <vtkPolyDataMapper.h>


VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)


int main()
{
    BRepPrimAPI_MakeBox mkBox(1., 2., 3.);
    const TopoDS_Shape& Shape = mkBox.Shape();

    vtkNew<vtkRenderWindow> Win;
    vtkNew<vtkRenderer> Render;
    Win->AddRenderer(Render);

    vtkNew<vtkInteractorStyleTrackballCamera> IStyle;
    vtkNew<vtkRenderWindowInteractor> IRender;

    IRender->SetRenderWindow(Win);
    IRender->SetInteractorStyle(IStyle);


    //Domain Data (TopoDS_Shape) to vtkPolyData
    vtkNew<IVtkTools_ShapeDataSource> OCCSource;
    OCCSource->SetShape(new IVtkOCC_Shape(Shape));

    //vtkMapper -> vtkActor
    vtkNew<vtkPolyDataMapper> Mapper;

    Mapper->SetInputConnection(OCCSource->GetOutputPort());
    
    vtkNew<vtkActor> Actor;
    Actor->SetMapper(Mapper);
    Render->AddActor(Actor);

    
    Win->Render();
    IRender->Start();


    return 0;
}

Please help me rectify it. I am using OpenCascade v7.5.0 and VTK v9.0.3.

lokit khemka
  • 349
  • 3
  • 11
  • 3
    _However, this error is only happening in debug mode and not in Release mode._ At least in Visual Studio with MSVC, `std::vector::operator[]()` has an `assert()` with an index-range check. (It might be similar in other platforms/libraries as well - I don't know.) In Release, when `NDEBUG` is defined, this check is disabled. That doesn't mean that your error isn't there anymore. You should consider this seriously and investigate into this. (If you don't this will strike back if you don't expect it and things will become even worse.) – Scheff's Cat Aug 01 '21 at 06:52
  • Precisely, I am unable trace the source of the error. It is happening in the line with 'SetInputConnection' function. But, this is a very simple VTK program, I copied from VTK tutorial. How do I fix it? – lokit khemka Aug 01 '21 at 06:58
  • `assert()` calls `abort()` finally. That means a "forced crash". The advantage of this intentional crash: You get a core dump (in Linux and something comparable in Windows). This allows to explore the stack trace where you find which function called which with what arguments, and local variables will be there as well. Go "up" in the stack trace and check what called what. There should/must be something which is not called properly. (Or, VTK is broken. That's possible as well but most often the caller is the problem but not the callee - in 9 of 10 cases maybe.) ;-) – Scheff's Cat Aug 01 '21 at 07:02
  • Do you have some experience in debugging? If not - FYI: [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/7478597). Visual Studio has a _very_ good debugger. You should easily find online doc for it. – Scheff's Cat Aug 01 '21 at 07:04
  • If you copied the tutorial without any change, you could look for or post an issue on the Git Hub site. – Scheff's Cat Aug 01 '21 at 07:05
  • 1
    It *might* be related to a bug introduced by VTK 9.0 due to broken rounding of array sizes. OCCT 7.6.0dev has a workaround for it https://tracker.dev.opencascade.org/view.php?id=32331 – gkv311 Aug 01 '21 at 07:18

0 Answers0