[vtkusers] Fwd: Re: segfault when vtkXMLMultiBlockDataReader reads a .vtm binary mode - bug?
Tanaka Simon
tanakas at gmx.ch
Tue Dec 9 05:38:01 EST 2014
Dear Developers and Users,
I'll warming up this issue again since there was no echo last time.
Can somebody confirm the buggy behaviour of the following code:
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkXMLMultiBlockDataWriter.h>
#include <vtkXMLMultiBlockDataReader.h>
#include <vtkStringArray.h>
#include <sys/stat.h>
#include <sstream>
int main(int, char *[])
{
/**
* notes:
* -> it works with ascii writer configuration for any M,N.
* -> with binary writer configuration it segfaults for higher M,N
* -> {N=100,M=1} works. {N=100,M=10} fails. {N=1000,M=1} fails.
*/
const unsigned int N = 1000; // number of points
const unsigned int M = 1; // number of characters in the string
std::string filename = "test_output.vtm";
std::stringstream mystring;
struct stat buffer;
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkStringArray> stringAttribute =
vtkSmartPointer<vtkStringArray>::New();
vtkSmartPointer<vtkPolyData> mypolydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkMultiBlockDataSet> multiBDS =
vtkSmartPointer<vtkMultiBlockDataSet>::New ();
vtkSmartPointer<vtkXMLMultiBlockDataWriter> writer =
vtkSmartPointer<vtkXMLMultiBlockDataWriter>::New();
vtkSmartPointer<vtkMultiBlockDataSet> multiBDS_read =
vtkSmartPointer<vtkMultiBlockDataSet>::New ();
vtkSmartPointer<vtkXMLMultiBlockDataReader> reader =
vtkSmartPointer<vtkXMLMultiBlockDataReader>::New();
stringAttribute->SetNumberOfComponents(1);
reader->SetFileName(filename.c_str());
writer->SetFileName(filename.c_str());
writer->SetDataModeToBinary(); // segfault
//writer->SetDataModeToAscii(); // works
// create some points:
for (int k=0; k<N; ++k) {
points->InsertNextPoint(0.0, 0.0, 0.0);
}
// create some string attributes:
for (int k=0; k<N; ++k) {
for (int i=0; i<M; ++i) {
mystring << "x";
}
stringAttribute->InsertNextValue(mystring.str().c_str());
}
// assemble and write to file:
mypolydata->SetPoints(points);
mypolydata->GetPointData()->AddArray(stringAttribute);
multiBDS->SetBlock(0,mypolydata);
writer->SetInput(multiBDS);
writer->Write();
//now read the file again:
if (stat (filename.c_str(), &buffer) == 0) {
reader->Update();
multiBDS_read->ShallowCopy(reader->GetOutput());
}
else {
std::cout<<"file not found."<<std::endl;
}
return EXIT_SUCCESS;
}
thank you.
Simon
-------- Forwarded Message --------
Subject: Re: [vtkusers] segfault when vtkXMLMultiBlockDataReader reads
a .vtm binary mode - bug?
Date: Tue, 04 Nov 2014 22:34:01 +0100
From: Tanaka Simon <tanakas at gmx.ch>
To: VTK Users <vtkusers at vtk.org>, vtk-developers at vtk.org
Dear Developers,
can somebody confirm the buggy behaviour?
i attached a yet simplified code to reproduce the segfault.
thanks
simon
btw: i use ubuntu 14.04 and gcc 4.7
On 03.11.2014 11:19, Tanaka Simon wrote:
> Dear Developers,
>
> Hello VTK users and developers,
>
> I attached a simple program which segfaults. please also have a look
> at the comments in the code.
>
> i want to:
> 1) write a vtkMultiBlockDataSet to a file
> 2) load it
>
> it only segfaults if the writer is set to binary mode, and only if the
> data exceeds a certain size. in ascii mode, everything is fine.
>
>
> this might be related:
> http://www.paraview.org/Bug/print_bug_page.php?bug_id=13294
>
>
> can you confirm that behaviour? what am i doing wrong? and if it is a
> bug, how can i work around?
>
> thank you very much
> simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141209/752c5b13/attachment.html>
-------------- next part --------------
cmake_minimum_required(VERSION 2.8)
PROJECT(vtk_weird_segfault)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(vtk_weird_segfault MACOSX_BUNDLE vtk_weird_segfault)
if(VTK_LIBRARIES)
target_link_libraries(vtk_weird_segfault ${VTK_LIBRARIES})
else()
target_link_libraries(vtk_weird_segfault vtkHybrid vtkWidgets)
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk_weird_segfault.cxx
Type: text/x-c++src
Size: 2546 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141209/752c5b13/attachment.cxx>
-------------- next part --------------
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list