SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-18-2010, 03:35 PM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
Attributes/Themes evaluated regardless of conditionals?

I am seeing some behavior which I can't quit figure out but seems that attributes and themes are evaluated regardless of the conditional to reach them? Is that correct?

For example:

if( Evaluates_To_True )
true
Do Something
else
attribute=Blah

Even if, the if clause evaluates to true, my attribute is being set. In my specific scenario this is inside a table, and the the attribute set to the result of a method call. The method call is now failing because an unexpected object is being passed in as the result of the conditional being ignored.

Has anyone seen this?
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #2  
Old 11-18-2010, 06:14 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Widget evaluation is a multipass process. The first pass happens when the menu is loaded, and instantiates every widget in every branch, including all of their widget properties. In the case of Attribute widget values, or any widget property with a dynamic value (i.e. one set to =expression), those expressions are evaluated as part of the widget instantiation. Conditional evaluation kicks in only during the actual rendering pass (for blue UI widgets) or action pass (for green process chains).

Bottom line is that you have to be prepared for your property expressions to be evaluated regardless of any conditionals guarding them.
__________________
-- Greg
Reply With Quote
  #3  
Old 11-18-2010, 06:36 PM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
Quote:
Originally Posted by GKusnick View Post
Widget evaluation is a multipass process. The first pass happens when the menu is loaded, and instantiates every widget in every branch, including all of their widget properties. In the case of Attribute widget values, or any widget property with a dynamic value (i.e. one set to =expression), those expressions are evaluated as part of the widget instantiation. Conditional evaluation kicks in only during the actual rendering pass (for blue UI widgets) or action pass (for green process chains).

Bottom line is that you have to be prepared for your property expressions to be evaluated regardless of any conditionals guarding them.
Well that is just cruel :-)
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #4  
Old 11-18-2010, 06:48 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
One trick I sometimes use is to replace a property value with an expression like this:

Code:
=If(true, value, DebugLog("message"))
Keeping one eye on the console window then gives me a pretty good idea of when (and how often) that expression is getting evaluated.

(If you're not familiar with the console window, it's a real-time display of the debug log in a DOS window; see p. 230 of the V7 manual. I highly recommend enabling it for any Studio or Java plugin work.)
__________________
-- Greg
Reply With Quote
  #5  
Old 11-18-2010, 06:52 PM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
Will inner expressions of conditionals inside of a theme widget also be evaluated regardless of the result of the outer condition? My testing says yes, but I can't quite figure out why.

For example, inside my theme widget I have the following for fontcolor:

=If(tvbrowser_Episodes_IsEpisode(SeasonEpisode),If(tvbrowser_Episodes_IsRecording(SeasonEpisode), "0xFF0000",gColorBasicWhite),gColorBasicWhite)

It seems like that inner If is evaluated inside the theme widget even if the first if is false. Just trying to verify it will go through any widgets evaluate everything, regardless of conditions inside the widgets themselves?
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #6  
Old 11-18-2010, 06:55 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
You could also just adjust your method to handle the first pass or invalid object(which is probably null). I did that will some of my calls and logged it to be sure it was only doing it on first pass.

Another thing before it bites you like it did me beforemenuload loads after the attribute widget pass and such as well.
Reply With Quote
  #7  
Old 11-18-2010, 07:07 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Bear in mind that there's nothing magic about If(); it's just a normal API call. And like any Java method call, all arguments are evaluated before being passed in to the method (which in this case, just returns one and discards the other). In that sense, If() is not equivalent to Java's ?: operator.

Less obvious is the fact that && and || in widget expressions always evaluate both operands. They do not short-circuit as their Java or C counterparts do.
__________________
-- Greg
Reply With Quote
  #8  
Old 11-19-2010, 07:08 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
We should probably put together a list of the common "gotcha's" of studio programming. Probably every one of us has been bitten by the "multipass" behavior as well as the BeforeMenuLoad hook behavior.

Greg - I have a challenge for you I would love it if we had "lint" for Studio that would catch common errors and display warnings for not so obvious behavior. It's probably a tall order but it would REALLY help Studio developers.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #9  
Old 11-19-2010, 11:38 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
Greg - I have a challenge for you I would love it if we had "lint" for Studio that would catch common errors and display warnings for not so obvious behavior. It's probably a tall order but it would REALLY help Studio developers.
If you set preload_expression_cache=true in your properties file, Studio will do a syntax check on all expressions when the STV is loaded. This should catch most errors that can be detected mechanically.

For subtle errors of the sort we've been discussing in this thread (such as whether it's safe to evaluate both sides of a conditional) it would take some pretty hard-core program-flow analysis to detect those.
__________________
-- Greg
Reply With Quote
  #10  
Old 11-19-2010, 02:20 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by GKusnick View Post
For subtle errors of the sort we've been discussing in this thread (such as whether it's safe to evaluate both sides of a conditional) it would take some pretty hard-core program-flow analysis to detect those.
You're just the man for the job
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Modifying attributes on AfterMenuLoad hook castylx SageTV Studio 16 02-10-2007 11:22 PM
Problem with file attributes ? 320x240 ? nerys SageTV Software 1 06-27-2005 04:47 AM


All times are GMT -6. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.