Board index FlightGear Development Aircraft

Nasal tooltip error caused by mouse-wheel

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Nasal tooltip error caused by mouse-wheel

Postby mhab » Wed Mar 25, 2015 10:52 pm

Hello

Sometimes the following or a similar error is written to the console (FG 3.4):

Code: Select all
Nasal runtime error: invalid format string
  at C:/FlightGear_340/data/Nasal/canvas/tooltip.nas, line 134
  called from: C:/FlightGear_340/data/Nasal/canvas/tooltip.nas, line 94
  called from: C:/FlightGear_340/data/Nasal/canvas/tooltip.nas, line 289
  called from: C:/FlightGear_340/data/Nasal/canvas/tooltip.nas, line 365


I can try all my hover settings in the animations and none will reproducibly cause the error.
I am not able to find the cause, what triggers the error when it happens ...

Any ideas ?

Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby Necolatis » Wed Mar 25, 2015 10:58 pm

What aircraft does it happen with?
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1872
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Wed Mar 25, 2015 11:00 pm

ec130
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby Necolatis » Wed Mar 25, 2015 11:17 pm

I cannot reproduce that in the EC130 from FGADDON. (in 3.5) If you use another version maybe check the <label>s in hovered-binding animations to see if something is off.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1872
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Thu Mar 26, 2015 8:21 am

It is not so easy to reproduce, as I already mentioned ...

I was wondering if uninitialized properties may cause this ?
I fixed a double used tooltip-id, which B.T.W. is not very easy to find ...
and even then got a message about an invalid printf format %s (or sprintf, not sure if I remember right)

Another thing maybe:
- click animation uses hover-tooltip
- binding in animation calls a function which itself shows tooltip ...
... so we end up with "fighting tooltips" maybe

Thanks for listening
Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Sat Mar 28, 2015 8:47 pm

Finally I can reproduce this ...

In EC130 the MMB drag changes the power setting of the Twist Grip and displays the setting by
Code: Select all
p = getprop("/controls/engines/engine/power");
gui.popupTip(sprintf("Twist Grip %d%%", 100 * p));

If I startup from scratch I can use the MMB without problems and get the popuptip displayed.

If e.g. I use an outside view, hover over a door, click it and then use the MMB drag I get Nasal tooltip errors on the console ...
Here is the hovered binding of an example.
It follows what is described in the wiki.

Code: Select all
    <hovered>
      <binding>
        <command>set-tooltip</command>
        <tooltip-id>doorfl</tooltip-id>
        <label>%s</label>
        <property>/instrumentation/doors/frontl/position-norm</property>
        <mapping>nasal</mapping>
        <script>
          var mode = ['open', 'close'];
          return mode[arg[0]];
        </script>
      </binding>
    </hovered>

I don't really understand the way it works, and as it seems it doesn't work very well ;-)
I have used this very often and would be happy to hear how to fix it ...

EDIT: In EC130 for the moment (end March 2015) all but one hover tooltip (altimeter) using Nasal scripting are deactivated in development repository on gitlab to minimize Nasal runtime errors until cause of problem is found

Thanks
Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Tue Mar 31, 2015 10:07 am

Hello

Some more details ... The call from ec130.nas
Code: Select all
      gui.popupTip(sprintf("Twist Grip %d%%", 100 * p));
When used before a hovered tooltip with Nasal scripting it works well.
When used after a hovered Nasal-scripting tooltip behaviour changes and causes a Nasal runtime error ...

What happens ?
1) gui.popupTip() uses
Code: Select all
    fgcommand("show-message", props.Node.new({ "label": label, "delay":delay }));
and causes a problem in tooltip.showMessage() function because of the following:
Here is "showMessage" function from "....\data\Nasal\canvas\tooltip.nas"
Code: Select all
var showMessage = func(node)
{
  var msgId = node.getNode("id");
  tooltip.setTooltipId((msgId == nil) ? 'msg' : msgId.getValue());
  innerSetTooltip(node);
  ...
>>>  var innerSetTooltip = func(node)
     {
       tooltip.setLabel(cmdarg().getNode('label').getValue());
       ...
  >>>  setLabel: func(msg)
       {
          me._label = msg;
          me._updateText();
       },

  >>>     _updateText: func
          {
            var msg = me._label;
            if (me._property != nil) {                <<<< me_property is NOT nil but it should, reason not clear at the moment
              var val = me._property.getValue() or 0;

              # https://code.google.com/p/flightgear-bugs/issues/detail?id=1454
              # wrap mapping in 'call' to catch conversion errors
              var val_mapped = call(me._remapValue, [val], me, nil, var err = []);
              if( size(err) )
                printlog(
                  "warn",
                  "Tooltip: failed to remap " ~ debug.string(me._property, 0) ~ ":\n"
                  ~ debug.string(err, 0)
                );

              print( "me._label: " ~ me._label ~ " val_mapped:" ~ val_mapped ~ " val:" ~ val );    <<< added for debugging, it shows
                                                                                                   <<< why the next statement causes a problem

              msg = sprintf(me._label, val_mapped or val);
            }

            me._text.setText(msg);
            me._updateBounds();
          },
...

The message from popupTip should be passed as: "Twist Grip 66%"
but msg in the example above is: msg = sprintf("Twist Grip 66%", "Altimeter: 30.09 inHg (1019 hPa)" or "30.09000000000003")
This causes an error for sure ...

More to come when I or someone else finds more ...
Mike-DE
Last edited by mhab on Tue Mar 31, 2015 10:52 pm, edited 1 time in total.
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby Necolatis » Tue Mar 31, 2015 9:46 pm

I think I know what causes this.

When nasal calls popupTip, it sets the label before setting the property (which will be nil). It then looks inside the label and the % at the end makes it think it should be replaced by something, and since the property is not set yet, it uses the property of the last shown tooltip called from xml. It gives an error however because % is not a valid sprintf statement.

Maybe if innersettooltip was formed like this:

Code: Select all
var innerSetTooltip = func(node)
{
   var propPath = cmdarg().getNode('property');
   if (propPath != nil) {
     var n = props.globals.getNode(propPath.getValue());
     tooltip.setProperty(n);
   } else {
      tooltip.setProperty(nil);
   }

   tooltip.setLabel(cmdarg().getNode('label').getValue());
   var measure = cmdarg().getNode('measure-text');
   if (measure != nil) {
       tooltip.setWidthText(measure.getValue());
   } else {
       tooltip.setWidthText(nil);
   }

   var mapping = cmdarg().getNode('mapping');
   if (mapping != nil) {
     var m = mapping.getValue();
     var f = nil;
     if (m == 'nasal') {
       f = compile(cmdarg().getNode('script').getValue());
     }

     tooltip.setMapping(m, f);
   } else {
     tooltip.setMapping(nil);
  }
}


Then the property is set first. You can try it and see if it works, did not try it out.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1872
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Tue Mar 31, 2015 10:09 pm

Hello

Thanks for the helpful hints...

Just quickly before I try on: I think for gui.popupTip() the property shouldn't be set at all !!!

in the _updateText: func
the "if (me._property != nil)" ... is nil when the gui.popupTip() call works well
but it is !=nil when it fails.

So my approach was to find a way to reset the property to nil, if it is not needed ?!

Thanks
Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Tue Mar 31, 2015 11:12 pm

Hello
It is correct that if I avoid the % sign at the end of the gui.popupTip() no Nasal error is rased.

If I try Necolatis suggestion ... sad news: It doesn't work

Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby wkitty42 » Wed Apr 01, 2015 12:33 am

something i've run into... have you tried to add another % to the end and then seeing if it parses properly after (apparently) being ""double decoded""?

[anecdote] i ran into something very similar in my OS/2 system's 4OS2 interpreter yesterday... supposedly one doesn't need trailing % for vars but if two vars are to be put together to make one string then two % are needed (eg: %foo and then %bar should be together as %foo%%bar) but i found that i actually had to have three % as in %foo%%%bar... it was an eye opener and one found only after several hours of frustration and fighting to do what the documentation said should work and be operational... [/anecdote]
Last edited by wkitty42 on Wed Apr 01, 2015 5:02 pm, edited 1 time in total.
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 4749
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Nasal tooltip error caused by mouse-wheel

Postby Necolatis » Wed Apr 01, 2015 12:48 am

Yes, the property should be set,.but to nil. Otherwise it uses the property of the last shown tooltip. Trouble is the order it happens in.

I just reproduced the bug in 3.5 btw.

Replacing line 134 with this solved it for me, does it work for you too?

Code: Select all
      call(func {msg = sprintf(me._label, val_mapped or val)}, nil, nil, var err2 = []);
      if( size(err2) )
        printlog(
          "warn",
          "Tooltip: failed to assign label " ~ debug.string(me._property, 0) ~ ":\n"
          ~ debug.string(err2, 0)
        );
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1872
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Wed Apr 01, 2015 10:45 pm

Yes !!! That's it.
Fixed it for me too.

@Nicolatis: Will you take care this get's into FG 3.5/3.6 ?

Thanks a lot
Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Re: Nasal tooltip error caused by mouse-wheel

Postby Necolatis » Thu Apr 02, 2015 9:51 pm

I am not completely setup for doing merge requests to the new repo yet, but can do when I get it setup. :)
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore


Hangar: https://sites.google.com/site/fghangar/
User avatar
Necolatis
 
Posts: 1872
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2018.2.2
OS: Windows 10 Pro

Re: Nasal tooltip error caused by mouse-wheel

Postby mhab » Fri Apr 03, 2015 12:09 am

Hello

To make things more official I entered a new issue in the BUG Tracker ... see issue #1732 Nasal runtime error with hovered tooltip+gui.popupTip

Mike-DE
mhab
 
Posts: 404
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2017.1.2
OS: Win7

Next

Return to Aircraft

Who is online

Users browsing this forum: Google [Bot] and 7 guests