bugGNU Octave - Bugs: bug #57449, struct2hdl fails to set property...


bug #57449: struct2hdl fails to set property with erroneous "invalid value"

Submitted by:  None
Submitted on:  Thu 19 Dec 2019 01:55:31 PM UTC  
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  dev
Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 06 Jan 2020 07:32:24 AM UTC, comment #4: 

(Sorry for the late reply) Thank you for suggestion, I indeed proposed to generalise the default behaviour on the Maintainers e-mail list.

Fri 20 Dec 2019 04:44:33 PM UTC, comment #3: 

I think both conventions are reasonable.  Not creating an object if it cannot be rendered as the programmer intended (for example, because property/value pairs are incorrect) makes it clear that something is wrong to the user.  And, for laziness, this behavior is already programmed in to Octave.

On the other hand, Octave does not have to follow Matlab on this convention if we don't want to.  I would say that try/catch blocks aren't that expensive in terms of performance and struct2hdl isn't called in the innermost loops of functions so it is not going to be a hot spot in the code.  Performance is probably more related to how many properties you can modify in one call to set() versus multiple calls.

You could ask about changing the default behavior on the Octave Maintainers e-mail list if you wanted to get an opinion about going forward.  If they think it is a good idea then you could submit your patched up struct2hdl.m to this bug report for review.

Rik <rik5>
Project Administrator
Fri 20 Dec 2019 06:39:11 AM UTC, comment #2: 

Thank you for clearing up the fontweight issue that fast - I'm using Matlab R2010a, where this option is still available, and didn't think of reading the NEWS file ...

Regarding Octave ignoring the element with an invalid property: I've just noticed that Octave behaves just like Matlab in that case. For example, you can make a slider disappear from the GUI by setting its value outside of the range:

Warning: slider control can not have a Value outside of Min/Max range
Control will not be rendered until all of its parameter values are valid

Is it intended to copy that behaviour and only render the element if all values are valid? I'm aware that the try-catch-blocks in my workaround do slow things down.

Thu 19 Dec 2019 05:12:09 PM UTC, comment #1: 

Separate from whether struct2hdl should ignore an element which has errors during creation, the cause of this particular failure are the allowed values for the "FontWeight" property.

Matlab has deprecated and removed "demi" and "light", which leaves allowable values of "normal" or "bold".  See documentation at https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.text-properties.html.

Octave has followed Matlab's behavior in order to remain compatible.  In the NEWS file for what will become the Octave 6 release there is this statemnt:

### Removed functions and properties

The following functions and properties were deprecated in Octave 4.4
and have been removed from Octave 6.

- Functions

  Function             | Replacement
  `chop`               | `sprintf` for visual results
  `desktop`            | `isguirunning`
  `tmpnam`             | `tempname`
  `toascii`            | `double`
  `java2mat`           | `__java2mat__`

- Properties

  Object               | Property                  | Value
  `annotation`         | `edgecolor ("rectangle")` |
  `axes`               | `drawmode`                |
  `figure`             | `doublebuffer`            |
                       | `mincolormap`             |
                       | `wvisual`                 |
                       | `wvisualmode`             |
                       | `xdisplay`                |
                       | `xvisual`                 |
                       | `xvisualmode`             |
  `line`               | `interpreter`             |
  `patch`              | `interpreter`             |
  `surface`            | `interpreter`             |
  `text`               | `fontweight`              | `"demi"` and `"light"`
  `uibuttongroup`      | `fontweight`              | `"demi"` and `"light"`
  `uicontrol`          | `fontweight`              | `"demi"` and `"light"`
  `uipanel`            | `fontweight`              | `"demi"` and `"light"`
  `uitable`            | `fontweight`              | `"demi"` and `"light"`

Rik <rik5>
Project Administrator
Thu 19 Dec 2019 01:55:31 PM UTC, original submission:  

When I try to open a .fig-file which contains some ui element that has, for some reason, an invalid value in some property, then I can open the figure but the ui element isn't there at all.

Some background on this: I created a GUI in Matlab via GUIDE. I implemented simple text fields and set the fontweight to "demi" - since this property is known both in Octave and Matlab. I then call openfig() on the .fig-file in Octave, but in struct2hdl it fails to set the fontweight to "demi":

error: invalid value = demi
error: called from
    struct2hdl>setprops at line 630 column 12
    struct2hdl at line 196 column 3
    struct2hdl at line 190 column 15
    hgload at line 98 column 10
    openfig at line 113 column 8

I don't know what the underlying issue is, but I observed this behaviour for text->fontweight: demi and uipanel->title, even though both of these properties / values are known to Octave. (I therefore assigned this bug as a Matlab compatibility issue, but please correct me if I'm wrong)

The current output is no ui element at all if it contained an invalid value, no matter at which property fails in set(). As an alternative, I'd like to see the ui element but maybe with a default value for this property.
Currently, the code in the subfunction setprops() starting at line 627 looks like:

nh = length (hdls);
msg = "";
if (! nh)
   set (h, s.properties);

I'd propose a nested try-catch-block in the if(!nh) - case. My current workaround looks like this:

set (h, s.properties);
temp = fieldnames(s.properties);
for ind = 1:length(temp)
    set (h,temp{ind}, s.properties.([temp{ind}]));
    warning(['struct2hdl: failed to set the following property: ', temp{ind},' of ', s.properties.tag,' , restored to default value']);

This way I can see which property of which element failed while I can still interact with my element, since every property has a default value.

Since the issues with opening a Matlab-created .fig-file in Octave are discussed elsewhere, I'd link bug #44670.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.5