[vtkusers] Crash in vtkOpenGLContextDevice2D::ComputeStringBounds when getting bounding rect of vtkAxis
Elvis Stansvik
elvis.stansvik at orexplore.com
Sun Feb 12 06:50:12 EST 2017
2017-02-12 12:30 GMT+01:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
> Hi all,
>
> In the test case below, I'm trying to get the bounding rect of a vtkAxis
> in a vtkChartXY, but I'm getting a crash in the call to GetBoundingRect
> with the following backtrace:
>
> #0 vtkOpenGLContextDevice2D::ComputeStringBounds (this=this at entry=0x689ea0,
> string=..., bounds=bounds at entry=0x7fffffffcda0)
> at /buildbot/vtk7-builder/build/Rendering/ContextOpenGL2/
> vtkOpenGLContextDevice2D.cxx:1755
> #1 0x00007ffff78454f1 in vtkOpenGLContextDevice2D::ComputeStringBounds
> (this=0x689ea0, string=..., bounds=0x7fffffffcda0)
> at /buildbot/vtk7-builder/build/Rendering/ContextOpenGL2/
> vtkOpenGLContextDevice2D.cxx:1626
> #2 0x00007ffff6f2722d in vtkContext2D::ComputeStringBounds
> (this=this at entry=0x67e3f0, string=..., bounds=bounds at entry=0x7fffffffcda0)
> at /buildbot/vtk7-builder/build/Rendering/Context2D/vtkContext2D.cxx:645
> #3 0x00007ffff7ab4b28 in vtkAxis::GetBoundingRect (this=0x671490,
> painter=0x67e3f0) at /buildbot/vtk7-builder/build/
> Charts/Core/vtkAxis.cxx:990
> #4 0x0000000000402ab1 in main (argc=1, argv=0x7fffffffd038) at
> /home/estan/testcrash/main.cpp:50
>
> The reason seems to be that the render window (RenderWindow member) of
> vtkOpenGLContextDevice2D is NULL at that point (!).
>
> Am I using the GetBoundingRect API in the wrong way somehow? How can I get
> the computed bounding rect for a vtkAxis?
>
I realize now that RenderWindow of the vtkOpenGLContextDevice2D is only
valid during a paint (between Begin() and End()). At other times it is
NULL. So is it not safe to call vtkAxis::GetBoundingRect(..) except during
rendering..? If so, is there any other way to get the bounding rect of a
vtkAxis as a user?
Elvis
> Thanks in advance,
> Elvis
>
> main.cpp:
>
> #include <vtkAxis.h>
> #include <vtkChartXY.h>
> #include <vtkContextScene.h>
> #include <vtkContextView.h>
> #include <vtkFloatArray.h>
> #include <vtkNew.h>
> #include <vtkPlot.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkTable.h>
>
> int main(int argc, char *argv[]) {
> vtkNew<vtkRenderer> renderer;
>
> vtkNew<vtkRenderWindow> window;
> window->AddRenderer(renderer.Get());
>
> vtkNew<vtkRenderWindowInteractor> interactor;
> interactor->SetRenderWindow(window.Get());
>
> vtkNew<vtkChartXY> chart;
>
> vtkNew<vtkTable> table;
> vtkNew<vtkFloatArray> xArray;
> xArray->SetName("X Axis");
> table->AddColumn(xArray.Get());
> vtkNew<vtkFloatArray> yArray;
> yArray->SetName("Y Axis");
> table->AddColumn(yArray.Get());
> table->SetNumberOfRows(2);
> table->SetValue(0, 0, 0);
> table->SetValue(0, 1, 0);
> table->SetValue(1, 0, 1);
> table->SetValue(1, 1, 1);
>
> auto linePlot = chart->AddPlot(vtkChart::LINE);
> linePlot->SetInputData(table.Get(), 0, 1);
>
> vtkNew<vtkContextView> view;
> view->GetScene()->AddItem(chart.Get());
> view->SetRenderWindow(window.Get());
> view->SetInteractor(interactor.Get());
>
> window->Render();
>
> // Get bounding rect of the left axis
> auto leftAxis = chart->GetAxis(vtkAxis::LEFT);
> leftAxis->Update();
> auto rect = leftAxis->GetBoundingRect(view->GetContext());
>
> interactor->Start();
>
> return 0;
> }
>
>
> CMakeLists.txt:
>
> cmake_minimum_required(VERSION 3.1)
>
> project(TestCase)
>
> set(CMAKE_CXX_STANDARD 11)
> set(CMAKE_CXX_STANDARD_REQUIRED ON)
>
> find_package(VTK COMPONENTS
> vtkChartsCore
> vtkCommonCore
> vtkInteractionStyle
> vtkRenderingContext2D
> vtkRenderingContextOpenGL2
> vtkRenderingCore
> vtkRenderingFreeType
> vtkRenderingOpenGL2
> vtkViewsContext2D
> )
>
> add_executable(TestCase main.cpp)
>
> target_link_libraries(TestCase PUBLIC
> vtkChartsCore
> vtkCommonCore
> vtkInteractionStyle
> vtkRenderingContext2D
> vtkRenderingContextOpenGL2
> vtkRenderingCore
> vtkRenderingFreeType
> vtkRenderingOpenGL2
> vtkViewsContext2D
> )
>
> target_include_directories(TestCase PUBLIC
> ${VTK_INCLUDE_DIRS}
> )
>
>
>
>
>
> target_compile_definitions(TestCase PUBLIC
>
>
>
> ${VTK_DEFINITIONS}
>
>
>
> )
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170212/ab484dae/attachment.html>
More information about the vtkusers
mailing list