[vtkusers] vtkWindow SetWindowName

Antoine Rosset rossetantoine at bluewin.ch
Sat Apr 5 03:40:35 EDT 2008


I think there are bugs in the SetWindowName implementation of many  
subclasses of vtkWindow

SetWindowName should support NULL pointer, used for example in the  
destructor of vtkWindow, to release the string pointer, but many  
subclasses don't support the NULL pointer and generate crashes, see:

void vtkCarbonRenderWindow::SetWindowName( const char * _arg )
{
   vtkWindow::SetWindowName(_arg);

   if(this->OwnWindow)
     {
     CFStringRef newTitle =
       CFStringCreateWithCString(kCFAllocatorDefault, _arg,
                                 kCFStringEncodingASCII);
     SetWindowTitleWithCFString(this->RootWindow, newTitle);
     CFRelease(newTitle);
     }
}


CFStringCreateWithCString doesnt support NULL

void vtkOSOpenGLRenderWindow::SetWindowName(const char * cname)
{
   char *name = new char[ strlen(cname)+1 ];
   strcpy(name, cname);
   vtkOpenGLRenderWindow::SetWindowName( name );
   delete [] name;
}

strlen doesnt support NULL, strcpy doesnt support NULL


void vtkXOpenGLRenderWindow::SetWindowName(const char * cname)
{
   char *name = new char[ strlen(cname)+1 ];
   strcpy(name, cname);
   XTextProperty win_name_text_prop;

   vtkOpenGLRenderWindow::SetWindowName( name );

   if (this->Mapped)
     {
     if( XStringListToTextProperty( &name, 1, &win_name_text_prop ) ==  
0 )
       {
       XFree (win_name_text_prop.value);
       vtkWarningMacro(<< "Can't rename window");
       delete [] name;
       return;
       }

     XSetWMName( this->DisplayId, this->WindowId, &win_name_text_prop );
     XSetWMIconName( this->DisplayId, this->WindowId,  
&win_name_text_prop );
     XFree (win_name_text_prop.value);
     }
   delete [] name;
}

again no support for NULL

void vtkCocoaRenderWindow::SetWindowName( const char * _arg )
{
   vtkWindow::SetWindowName(_arg);
   if (this->GetWindowId())
     {
     NSString* winTitleStr;

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040
     winTitleStr = [NSString stringWithCString:_arg  
encoding:NSASCIIStringEncoding];
#else
     winTitleStr = [NSString stringWithCString:_arg];
#endif

     [(NSWindow*)this->GetWindowId() setTitle:winTitleStr];
     }
}

NSString stringWithCString doesn't support NULL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080405/97e73568/attachment.htm>


More information about the vtkusers mailing list