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

 
 

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

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

Add a New Comment Rich Markup
   

Mon 27 Apr 2020 11:22:24 PM UTC, comment #5: 

I think we'll just continue to be Matlab compatible here and not create a graphics object if the property/value pairs are incorrect.

Rik <rik5>
Group administrator
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.

Anonymous
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>
Group 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:

set(handles.result_resolution_slider,'Value',-1)
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.


Anonymous
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>
Group 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);
 else
...


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

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

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.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-04-27 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code