MantisBT - KWWidgets
View Issue Details
0007141KWWidgetspublic2008-06-02 16:432008-06-03 09:29
kentwilliams 
Yumin Yuan 
normalminoralways
resolvedfixed 
0007141: vtkKWLoadSaveDialog initially lists '1' as the file type in the 'Files of type:' combo box.
vtkKWLoadSaveDialog initially lists '1' as the file type in the 'Files of type:' combo box.
I tracked this down and provide a patch.

The problem is this: first, a call to vtkKWComboBox::GetValueFromIndex() is made. This calls this->Script to get the value out of the TK widget.

Then a call is made to vtkKWComboBox::SetValue(), which calls vtkKWWidget::IsAlive(), which calls vtkKWWidget::IsAlive(), which calls vtkKWApplication::EvaluateBooleanExpression() which calls vtkKWTkUtilities::EvaluateString() to get the value.

But ... deep breath ... EvaluateString is the same function that vtkKWComboBox::GetValueFromIndex() calls to get the Nth string from the Combo box widget. And EvaluateString returns a static char * value that is overwritten every time it is called.

The solution is to save the string returned from GetValueFromIndex, before calling SetValue.
No tags attached.
patch vtkKWFileBrowserDialog.cxx.patch (1,175) 2008-06-02 16:43
https://public.kitware.com/Bug/file/1512/vtkKWFileBrowserDialog.cxx.patch
Issue History
2008-06-02 16:43kentwilliamsNew Issue
2008-06-02 16:43kentwilliamsFile Added: vtkKWFileBrowserDialog.cxx.patch
2008-06-03 08:51Sebastien BarreStatusnew => assigned
2008-06-03 08:51Sebastien BarreAssigned To => Yumin Yuan
2008-06-03 09:24Yumin YuanNote Added: 0012210
2008-06-03 09:28Yumin YuanNote Added: 0012211
2008-06-03 09:29Yumin YuanStatusassigned => resolved
2008-06-03 09:29Yumin YuanResolutionopen => fixed

Notes
(0012210)
Yumin Yuan   
2008-06-03 09:24   
CVS commit
BUG: Try the fix again. (silly me for last reverse). The returned
value (const char*) from vtkKWComboBox::GetValueFromIndex() is only
pointing to a temporary buffer, and it should be copied locally for
later use.

FYI, Patrick Emond reported this problem a couple weeks ago, and I
committed a fix, but later I reversed that fix because the File
Browser was broken due to other changes in vtksys, and I never put
that fix back in after figuring out why the file browser was broken.


On Mon, Jun 2, 2008 at 4:58 PM, kent williams <nkwmailinglists@gmail.com> wrote:
> I logged this in Mantis -- http://www.itk.org/Bug/view.php?id=7141 [^] --
> I provide a patch for this specific problem, but I worry that there
> are other potential issues elsewhere in KWWidgets.

> ...

There are some other methods in KWW classes, just like
vtkKWComboBox::GetValueFromIndex() , the returned value is a pointer
to a temporary buffer, which should be copied *immediately* to your
own storage. If you grep *temporary buffer* in KWW header files, you
will see most (if not all) of these methods.
Apparently, the doc (comments) for vtkKWComboBox::GetValueFromIndex()
did not say that :-(, and I added comments to show this *feature*.
(0012211)
Yumin Yuan   
2008-06-03 09:28   
More comments from Sebastien:


On Tue, Jun 3, 2008 at 8:56 AM, Sebastien BARRE <sebastien.barre@kitware.com> wrote:
> At 6/2/2008 10:58 PM, kent williams wrote:
>
>> What the bug comes down to is this: If you make any of the myriad
>> calls that end up using ad-hoc TCL scripts to pull values out of TK
>> widgets, you have to save the result before any calling any other
>> method that ends up using a TCL script.
>
> Yes, it's a well known issue, and we have tried to document it for every
> method that returns a pointer to that specific buffer (i.e. it mostly
> concerns methods returning char*). If it bites you in a specific class, let
> us know and we will add more documentation.
>