Bug in Effect.IsOFX when an effect is not an OFX

bvideo wrote on 8/4/2024, 4:28 PM

I'm attaching a script that shows an error. And a project, but you can use another if you want.

The bug occurs when an event has a non-OFX effect on it. Yes, those are a little harder to find now, but when it does happen, if a script invokes the 'IsOFX' primitive on that effect it throws an exception. "IsOFX" is implemented as a magic "get => " and does something improper behind the scenes. On the other hand, finding the same effect in the 'vegas.PlugIns' list of effects and using that 'IsOFX' does not fail.

Instructions: put the script in your folder and open a project, or my project. Select a video event that has a non-OFX effect. My project has one event with 3 effects, one of them is non-OFX.

Then run the script. On my 21.314 system it logs its perusal of event effects and traps an exception when it tries to access the event's non-OFX effect's primitive 'IsOFX'. A dialog shows the exception, and exiting the dialog shows the sequence of traversing the effects up to the point of failure.

My project:

https://drive.google.com/file/d/1gNmYXUemcM0Mk3_W6sTOnpF5-jwXCoiU/view?usp=drive_link

My script:

using System;
using System.Windows.Forms;
using ScriptPortal.Vegas;

class EntryPoint
{
    private Vegas veg;
    private LogFile log;
    public void FromVegas(Vegas vegas)
    {
        veg = vegas;
        foreach (Track track in veg.Project.Tracks) {
            if (track.MediaType == MediaType.Video) {
                foreach (VideoEvent ve in track.Events) {
                    if (ve.Selected)
                        foreach (Effect ef in ve.Effects) {
                            if (log == null)
                                log = new LogFile();
                            log.AddLogEntry("Effect name: " + ef.PlugIn.Name);
                            PlugInNode pn = vegas.PlugIns.FindChildByName(ef.PlugIn.Name);
                            if (pn != null) {
                                log.AddLogEntry("..Found it in the vegas plugin list");
                                try {
                                    log.AddLogEntry("....Trying 'IsOFX' from the plugin list");
                                    if (pn.IsOFX)
                                        log.AddLogEntry("....successful: it is OFX");
                                    else
                                        log.AddLogEntry("....successful: it is not OFX");                                }
                                catch (Exception ex) {
                                    veg.ShowError("Caught trying 'pn.IsOFX' for '" + ef.PlugIn.Name + "' in the Vegas.PlugIns list:\r\n" + ex.Message);
                                    log.ShowLogAsDialog("after exception");
                                    throw;
                                }
                            }
                            try {
                                log.AddLogEntry("..Now trying 'IsOFX' as an effect plugin");
                                if (ef.IsOFX)
                                    log.AddLogEntry("....successful: it is OFX");
                                else
                                    log.AddLogEntry("....successful: it is not OFX");                            }
                            catch (Exception ex) {
                                veg.ShowError("Caught exception trying 'ef.IsOFX' for '" + ef.PlugIn.Name + "' as an effect plugin:\r\n" + ex.Message);
                                log.AddLogEntry("Exception: " + ex);
                                log.ShowLogAsDialog("after exception");
                                throw;
                            }
                        }
                }
            }
        }
        if (log == null)
            veg.ShowError("Select a video event with effects");
        else
            log.ShowLogAsDialog("Complete");
    }
}

I encountered this in a larger context of a custom command that surveys stuff. I tried hard to find a test case for non-OFX, and sure enough it failed.

P.S. when I view this as a post, it appears there is a missing '}'. But when I go to edit it, the '}' is there. It's the end of the first 'try' block before the 'catch'. Watch out for that.

PPS: Oh it is there, it's just scrolled way to the right. Watch out for it anyway.

Comments

zzzzzz9125 wrote on 8/4/2024, 7:49 PM

I can confirm that this bug exists, and I've encountered it before. My solution is to use Effect.PlugIn.UniqueID.Contains("{Svfx:") instead of Effect.IsOFX to determine if it's an OFX effect.

Using VEGAS Pro 22 build 248 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

jetdv wrote on 8/4/2024, 8:41 PM

@bvideo, a couple of questions...

1. What does your log say?

2. Why do you have this in there at all?

                            PlugInNode pn = vegas.PlugIns.FindChildByName(ef.PlugIn.Name);
                            if (pn != null) {
                                log.AddLogEntry("..Found it in the vegas plugin list");
                                try {
                                    log.AddLogEntry("....Trying 'IsOFX' from the plugin list");
                                    if (pn.IsOFX)
                                        log.AddLogEntry("....successful: it is OFX");
                                    else
                                        log.AddLogEntry("....successful: it is not OFX");                                }
                                catch (Exception ex) {
                                    veg.ShowError("Caught trying 'pn.IsOFX' for '" + ef.PlugIn.Name + "' in the Vegas.PlugIns list:\r\n" + ex.Message);
                                    log.ShowLogAsDialog("after exception");
                                    throw;
                                }
                            }

It seems redundant to "find" an effect you already have in the variable ef and are doing the exact same check on ef in the next section.

bvideo wrote on 8/4/2024, 10:10 PM

@jetdv Apparently it's not the same check. It's being done on a PlugInNode: 'pn.IsOFX', as opposed to an Effect: 'ef.IsOFX'. And it works. Whereas the check on an Effect (in the next section) on 'ef.IsOFX' causes an exception. (If I understand your question)

My aim in writing this script was to demonstrate that for an effect I find in the timeline, first try a workaround to see if finding it in the 'Vegas.PlugIns' list and testing to see if that implementation of 'IsOFX' (in PlugInNode) works. Then in the next section, try my original code which was the more natural thing to do, 'ef.IsOFX', which I had previously found to crash. Use both attempts with try-catch to show any exceptions. So this script is just a demo, and is not really for doing anything else useful.

Here's the output from running the script on an Event on which I had three random effects: "Hand Drawn", "HSL Adjust", and "Swirl" (which is the non-OFX effect).

The exception (my veg.ShowError(...)):

 

Here's all the text from my log displayed after the above dialog:

(my log.ShowLogAsDialog("after exception");)

Effect name: Hand Drawn
..Found it in the vegas plugin list
....Trying 'IsOFX' from the plugin list
....successful: it is OFX
..Now trying 'IsOFX' as an effect plugin
....successful: it is OFX
Effect name: HSL Adjust
..Found it in the vegas plugin list
....Trying 'IsOFX' from the plugin list
....successful: it is OFX
..Now trying 'IsOFX' as an effect plugin
....successful: it is OFX
Effect name: Swirl
..Found it in the vegas plugin list
....Trying 'IsOFX' from the plugin list
....successful: it is not OFX
..Now trying 'IsOFX' as an effect plugin
Exception: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at ScriptPortal.Vegas.IOFXPlugCOM.GetUniqueID(String& val)
   at ScriptPortal.Vegas.Effect.get_OFXEffect()
   at EntryPoint.FromVegas(Vegas vegas)

Then after my script bails with the 'throw', the full error dialog is this:

@zzzzzz9125 your workaround looks good. My use of 'ef.Name' is not really good because there are duplicate names in the vegas plugin list.

But now I see this works: Effect.PlugIn.IsOFX (cf: ef.PlugIn.IsOFX).

 

zzzzzz9125 wrote on 8/4/2024, 11:45 PM

But now I see this works: Effect.PlugIn.IsOFX (cf: ef.PlugIn.IsOFX).

@bvideo A better solution👍

Just tested it on the script I had this problem with earlier and it works fine, such as the following code:

            if (sourceEffect.PlugIn.UniqueID.Contains("{Svfx:")) // when the plugin is a DXT plugin, sourceEffect.IsOFX will throw an error, so I judge it by GUID strings
            {
                CopyOFX(sourceEffect.OFXEffect, targetEffect.OFXEffect);
            }

Change it to:

            if (sourceEffect.PlugIn.IsOFX)
            {
                CopyOFX(sourceEffect.OFXEffect, targetEffect.OFXEffect);
            }

This will not throw an error either.

Last changed by zzzzzz9125 on 8/4/2024, 11:49 PM, changed a total of 4 times.

Using VEGAS Pro 22 build 248 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70