Re: A GNUstep template to replace WMText dockapp

Patrick CARDONA <[email protected]> Fri, 20 Mar 2026 18:59:24 +0100
Newsgroups gmane.comp.lib.gnustep.general
Message-ID <53156a5b6ff7b4b2c27287523fa21410@pi500>
Hello,

I am stuck at stage 3 because of a segfault with the timer call...

On 2026-03-19 18:30:40 +0100 Patrick CARDONA <[email protected]> 
wrote:

> ...
> 
> I am working on an application to replace 'WMText' dockapp with a 
> more 
> powerfull and consistent GNUstep template.
> 
> (...)
> 
> Stages:
> (...) 
> 
> 
> 3- Adding dynamic text from an NStask output to retrieve external 
> infos ...

Well, here is the logic:

/*
  * How it works?
  * In applicationDidFinishLaunching method:
  * An empty Icon is created, with a menu...
  * A Timer calls every n seconds drawRepOnIcon method.
  * drawRepOnIcon method calls drawImageRep which calls getInfo.
  * getInfo gets output from an NSPipe from an NSTask call;
  * Then drawImageRep which draw getted text info on the Icon 
representation.
  * This representation is drawn on the Icon.
  * The Icon is associated as App Icon.
  *
  *   applicationDidFinishLaunching
  *           |___ (NSImage) iconImage  |  (NSMenu) menu
  *           |___ (NSTimer) timer
  *                            |_____ drawRepOnIcon
  *                                         |_______drawImageRep
  *                                                              
|_______ getInfo
  *                                                                     
          |_____ (NSTask) task | (NSPipe) outpipe
  *                                                                     
                                                              |__ 
(NSString) myText
  *
  */

If I remove timer stage and I call 'drawRepOnIcon' once:
> [self drawRepOnIcon]
well, the application is working as expected:

  *   applicationDidFinishLaunching
  *           |___ (NSImage) iconImage  |  (NSMenu) menu
  *           |_____ drawRepOnIcon
  *                               |_______drawImageRep
  *                                                      |_______ 
getInfo
  *                                                                     
    |_____ (NSTask) task | (NSPipe) outpipe
  *                                                                     
                                                        |__ (NSString) 
myText
  */

Using the timer I also added some cleaning to remove previous 
representation before writing again on the Icon, but I get a 
segmentation fault - I guess a memory issue - but without any clue as 
the app builds without any error nor warning.

This is the call of the timer:

> // Timer to call drawRepOnIcon every n sec.
> NSTimer *timer = AUTORELEASE([NSTimer scheduledTimerWithTimeInterval: 
> 10.0
>                       target: self
>                       selector:@selector(drawRepOnIcon)
>                       userInfo: nil 
>                       repeats:YES]);
> 
>     [timer fire];
> 

And below, the 'drawRepOnIcon' method:

> - (void) drawRepOnIcon
> {
>   // We retrieve last representation drawn on the Icon
>   NSImageRep *lastRep = [[iconImage representations] lastObject];
>   // We remove it...
>   [iconImage removeRepresentation: lastRep];
> 
>   // We initiate and put the new representation on the Icon
>   NSImageRep *rep = AUTORELEASE([[NSCustomImageRep alloc] 
>                                                 initWithDrawSelector: 
> @selector(drawImageRep)
>                                                 delegate:self]);
>   [rep setSize: NSMakeSize(48, 48)];
>   [iconImage addRepresentation: rep];
> }
> 

Help would be appreciated. Of course, no hurry.
I joined also the whole project as a tarball.


<AgnostepText_Template.tar.gz>


Kind Regards,
Patrick

-- 
Patrick Cardona - Pi500 - GNU/Linux aarch64 (Debian 13.4)
Xorg (1:7.7+24) - libcairo2 (1.18.4-1+rpt1 arm64) - Window Maker 
(0.96.0-4)
GWorkspace (1.1.0 - 02 2025) - Theme: AGNOSTEP - Classic - MUA: 
GNUMail (1.4.0 - rev.947)
AgnostepText_Template.tar.gz (application/x-gzip, 3.5 KB) - not displayed