[vtkusers] Trouble using vtkAxis->SetTitle

Riku subs at collab.se
Wed May 4 16:53:07 EDT 2011


Hello Daniel,

I recently had this very same problem. I also for some reason was
fiddling about with the vtkStdString initially -- unnecessarily. Now I
successfully use code very similar to you testing code below, in loads
of places.

You already hit the point in you mail, I think: it's about the
versions of the DLLs. I've found through experience that Debug builds
of my software need to be used together with Debug builds of VTK DLLs,
Release builds together with Release DLLs, etc. After making sure that
the builds of my software and the VTK DLLs match, I have no further
problems.

I hope this solves your issue. (Please let me know if so, or if not.)

Good luck,

Riku



2011/5/4 Frese Daniel Dr. <frese at heidenhain.de>:
> Hi Marcus,
>
> I simplified as much as I could. Here is the crashing
> program :
>
> #include "vtkAxis.h"
> #include <string>
>
> void main() {
>        std::string temp = "TestX";
>
>        vtkAxis *Xaxis = vtkAxis::New();
>        Xaxis->SetTitle(temp.c_str());
> }
>
> It crashes at the same line in vtkAxis.cxx as I wrote before.
>
> Testing a bit further, I noted that the program crashes only when built and
> run in Debug configuration, but it runs fine in Release. I am aware that in the
> Visual Studio Debug and Release versions can behave differently, but in my experience
> so far the Debug configuration was always more benign than the Release. So I had a few
> times the case that the Release version crashes while the Debug ran fine;
> but this time it's the other way around ?!
>
> The only lib I link for this test program is vtkAxis (although the behavior does not
> change when linking also other vtk libs additionally). I use in both cases (Debug and
> Release) the same vtkAxis.dll (built with the same compiler MSVC 2008 in "RelWithDebInfo" Config).
> Is this OK or do I have to built a second set of Debug libs for use in programs built
> in the Debug config ? Maybe this whole thing has nothing to do with vtkAxis, but is just a
> MSVC thing. On the other hand I've been working with vtk for a few months now and never built any
> Debug version of the lib, and is has been working fine so far...
>
> If anybody could shine some light on this, this would be great. I can also post/send a ZIP of the
> MSVC solution, but since this is about 400kB, I'd rather not "pollute" the whole mailing list with
> such an attachment. The program above is basically the main.cpp of a Win32 console application
> without any further whistles and bells.
>
> Daniel
>
> -----Ursprüngliche Nachricht-----
> Von: Marcus D. Hanwell [mailto:marcus.hanwell at kitware.com]
> Gesendet: Dienstag, 3. Mai 2011 16:31
> An: Frese Daniel Dr.
> Cc: vtkusers at vtk.org
> Betreff: Re: [vtkusers] Trouble using vtkAxis->SetTitle
>
> 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
>
>
> -------------------------------------------------------------------------------------------------------
> Registergericht: Traunstein / Registry Court: HRB 275 – Sitz / Head Office: Traunreut
> Aufsichtsratsvorsitzender / Chairman of Supervisory Board: Rainer Burkhard
> Geschäftsführung / Management Board: Thomas Sesselmann (Vorsitzender / Chairman),
> Michael Grimm, Matthias Fauser, Sebastian Tondorf
>
> E-Mail Haftungsausschluss / E-Mail Disclaimer: http://www.heidenhain.de/disclaimer
>
>
> _______________________________________________
> 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://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list