[vtkusers] Trouble using vtkAxis->SetTitle

Marcus D. Hanwell marcus.hanwell at kitware.com
Tue May 3 10:31:24 EDT 2011


2011/5/3 Frese Daniel Dr. <frese at heidenhain.de>:
> Hi !
>
> I am having some strange problem using vtkAxis->SetTitle() from the new
> charts API.
> After the second of the following lines an exception occurs:
>
>                 temp = XAxisName->c_str();
>                 Xaxis->SetTitle(temp);  // title of axis

What is XAxisName, and std::string? There is no need for the temp, but
you could use it (vtkStdString can be constructed in the function from
a const char* that is properly null terminated).
>
> Temp is of type vtkStdString and Xaxis of type vtkSmartPointer<vtkAxis>
> (although the behavior is essentially the same when I make Xaxis as a direct
> vtkAxis without any smart pointers).
> I checked that the value of temp at this point is well defined (“TestX”),
> and I can trace further until I arrive at
> void vtkAxis::SetTitle(const vtkStdString &title)
> {
>   if (this->Title != title)
>     {
>     this->Title = title;
>     this->Modified();
>     }
> }
>
> , which is defined in vtkAxis.cxx. The exception occurs when trying to
> execute the line this->Title = title;
> The odd thing – already indicating that something goes wrong – is that
> “title” seems to point four bytes before the right string and seems to be
> much longer; i.e. it shows XXXXTestXXXXXX…, where X is some arbitrary
> garbage byte.
>
> I am using Visual Studio 2008 on Win XP and get an exception message stating
> some memory corruption.
>
> Does anybody has a clue what’s going on here ? If I remove calls to SetTitle
> (I have two of them in my app), everything seems to run smoothly (apart from
> the missing labels of course).
>
I have not seen this, if you can create a minimal test case that
reproduces the error I could take a look. Maybe our Windows developers
have a better idea, but the VTK tests run regularly on Windows and set
the axis title using a const char *, which then uses the const char *
constructor to make a temporary vtkStdString.

Marcus



More information about the vtkusers mailing list