Vegas Pro scripting difficult exception issue while rendering

marcinzm wrote on 6/1/2022, 4:46 PM

Hello,

 

I wrote my own form application in C# in Visual Studio for rendering video and audio seperately and also combined as audio + video.

Yesterday everything was working fine, but today when I rendered a video from my application launched from Vegas Pro 19 I get the following error message:

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ApplicationException: Unhandled exception on main thread. ---> System.InvalidOperationException: Instance '5 C:' does not exist in the specified Category.
   at System.Diagnostics.CounterDefinitionSample.GetInstanceValue(String instanceName)
   at System.Diagnostics.PerformanceCounter.NextSample()
   at System.Diagnostics.PerformanceCounter.NextValue()
   at ScriptPortal.Vegas.DetailedRenderLibrary.DetailedRenderDialog.m_timer_Tick(Object sender, EventArgs e)
   at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at ScriptPortal.Vegas.IProjectCOM.Render(Object punkArgs, Int32& status)
   at VegasRenderingMZProject.Form1.fun_renderuj()
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   --- End of inner exception stack trace ---
   at ScriptPortal.Vegas.ScriptHost.HandleScriptThreadException(Object sender, ThreadExceptionEventArgs args)
   at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at ScriptPortal.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName)
   at ScriptPortal.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)
 

 

 

I don`t know what caused the problem. Is it a Vegas exception issue or maybe clearly C# issue not combined with Vegas Pro.

My application runs as dll library.

 

Could you help me in figureuing out the error?

Regards
Marcin

 

Comments

jetdv wrote on 6/2/2022, 9:50 AM

@marcinzm If I'm understanding, it starts, you select things, and then it is crashing before the render? After the render? Between two renders?

Without knowing anything about your code, it might be hard to diagnose.

Does this mean anything?

Instance '5 C:' does not exist in the specified Category.

 

marcinzm wrote on 6/2/2022, 10:30 AM

Rendering starts, it lasts a few hours, I think it crashes while rendering, between renderings or after rendering. Unfortunately I wasn't present in front of computer to see in what state it was generated.

I also do not know aht "5 C:" means. I think that it is the most wanted error meaning, because I think this error is the clue to solve the issue.

My GUI is in Polish language, so I think it is not good way to paste the GUI, but in a short:
I have 4 checkboxes - 3 of them let rendering audio and 1 of them let rendering video.

After rendering, the only the video is copy to net drive. Then, some specified url in chrome web browser is being fired. Finally the email is sent with confirmation that everything was done fine. Then if I need I shutdown PC, but it was not set in that case. Some specified narration sounds are played when rendering reaches 30%, 50%, 90% and one minute before end.

Stephen-DeChellis wrote on 6/2/2022, 5:24 PM

Are you rendering to your C: drive? It is likely a typo in your code.

Try rendering to a different drive and see if the error changes.

marcinzm wrote on 6/6/2022, 5:59 AM

My problem sometimes occurrs, sometimes not.

I searched internet and I found similar problem and the problem was related with no admin rights for application.

https://social.msdn.microsoft.com/Forums/en-US/f6e10a9b-cc49-4054-b912-d8ed3d351037/instance-name-of-instance-does-not-exist-in-the-specified-category?forum=iis7general

Maybe, that's why there is C: error text, because I have VP19 installed on C: system drive.

I don`t save rendering video in C:\ but A:\ drive.

Can you advice me how to add admin rights for my dll library for Vegas and how to properly add admin rights for Vegas Pro 19 and all VP19 projects I used to open?

Thank you

Marcin

 

jetdv wrote on 6/6/2022, 6:57 AM

Where is your "Temp" drive set?

You might try right-clicking the VEGAS icon and choose "Run as Administrator". Or right-click the VEGAS link on the desktop, choose "Properties" and change it to Run as Admin there (Shortcut tab - click on Advanced).

marcinzm wrote on 6/6/2022, 8:06 AM

@Stephen-DeChellis

marcinzm wrote on 6/6/2022, 8:08 AM

@jetdv

My VP19 temp drive is C:\Users\XXXX\AppData\Local\VEGAS Pro\19.0\

Ok. I noticed that Vegas Pro 19 ICON had admin rights, but previously saved VP project didn`t have admin rights, maybe it was the problem.

I will need some time to test it out.

marcinzm wrote on 6/6/2022, 3:37 PM

Unfortunately, adding admin rights for Vegas projects, didn`t help.

I turn off some features which tried to save txt in C:\Program files... folder, but it also didn`t help.

I noticed that the problem occurs while rendering, not after rendering. The problem occurs probably only while rendering video from own software.

 

My rendering codes is:

 

private void RenderStartedHandlerMZ(Object sender, EventArgs e)
        {
            //Thread.Sleep(3000);
            p_start_global = DateTime.Now;
            p_start_label.Text = p_start_global.ToString();
            lista_plikow_do_przetworzenia_start.Add(p_start_global);
        }

private void RenderStatusEventHandlerMZ(Object sender, RenderStatusEventArgs args)
        {
            //RenderStatus r = new RenderStatus();

            p_procent_renderingu_label.Text = args.PercentComplete.ToString() + "%";

            if (args.PercentComplete.Equals(30) && !p_czy_odtwarzam_aktualnie_dzwiek_global && !p_co_odtworzono_za_dzwiek_global.Equals("30_procent"))
            {
                p_czy_odtwarzam_aktualnie_dzwiek_global = true;
                p_co_odtworzono_za_dzwiek_global = "30_procent";
                Task.Run(() => {
                    if (!p_wylacz_dzwiek_chk.Checked)
                    {
                        SPlayer1.PlaySync();
                    }
                });
                
                p_czy_odtwarzam_aktualnie_dzwiek_global = false;
            }
            else if (args.PercentComplete.Equals(50) && !p_czy_odtwarzam_aktualnie_dzwiek_global && !p_co_odtworzono_za_dzwiek_global.Equals("50_procent"))
            {
                p_czy_odtwarzam_aktualnie_dzwiek_global = true;
                p_co_odtworzono_za_dzwiek_global = "50_procent";
                //SPlayer2.PlaySync();
                Task.Run(() => {
                    if (!p_wylacz_dzwiek_chk.Checked)
                    {
                        SPlayer2.PlaySync();
                    }
                });
                p_czy_odtwarzam_aktualnie_dzwiek_global = false;
            }
            if (args.PercentComplete.Equals(70) && !p_czy_odtwarzam_aktualnie_dzwiek_global && !p_co_odtworzono_za_dzwiek_global.Equals("70_procent"))
            {
                p_czy_odtwarzam_aktualnie_dzwiek_global = true;
                p_co_odtworzono_za_dzwiek_global = "70_procent";
                //SPlayer3.PlaySync();
                Task.Run(() => {
                    if (!p_wylacz_dzwiek_chk.Checked)
                    {
                        SPlayer3.PlaySync();
                    }
                });
                p_czy_odtwarzam_aktualnie_dzwiek_global = false;
            }
            else if (args.PercentComplete.Equals(90) && !p_czy_odtwarzam_aktualnie_dzwiek_global && !p_co_odtworzono_za_dzwiek_global.Equals("90_procent"))
            {
                p_czy_odtwarzam_aktualnie_dzwiek_global = true;
                p_co_odtworzono_za_dzwiek_global = "90_procent";
                //SPlayer4.PlaySync();
                Task.Run(() => {
                    if (!p_wylacz_dzwiek_chk.Checked)
                    {
                        SPlayer4.PlaySync();
                    }
                });
                p_czy_odtwarzam_aktualnie_dzwiek_global = false;
            }

            
            

            double p_duration_progress_procent=(double)Math.Round((double)(p_selection_duration_miliseconds_global * args.PercentComplete),1)/ (double)100;

            TimeSpan tsp = TimeSpan.FromMilliseconds(p_duration_progress_procent);

            p_progress_duration_label.Text = tsp.Hours.ToString("D2") + ":" + tsp.Minutes.ToString("D2") + ":" + tsp.Seconds.ToString("D2") + ":" + tsp.Milliseconds.ToString("D2");

            if (p_duration_progress_procent.Equals(100))
            {
                p_progress_duration_label.Text = p_selection_duration_label.Text;
            }

            p_czas_teraz = DateTime.Now;

            

            if (p_czas_wczesniej.Year >= p_czas_teraz.Year && !(args.PercentComplete - p_procent_prev).Equals(0) && !p_procent_prev.Equals(-1) && !p_blokada_obliczen)
            {
                p_blokada_obliczen = true;
                TimeSpan tx = p_czas_teraz.Subtract(p_czas_wczesniej);
                //args.PercentComplete - p_procent_prev - tx.TotalMilliseconds
                //100 - X

                double tx_ile_czasu = tx.TotalMilliseconds * 100 / (double)(args.PercentComplete - p_procent_prev);
                double tx_ile_czasu_zostalo = tx.TotalMilliseconds * (100 - args.PercentComplete) / (double)(args.PercentComplete - p_procent_prev);

                TimeSpan tx_ile_bedzie_trwal_lacznie_rendering_tsp = TimeSpan.FromMilliseconds(tx_ile_czasu);
                TimeSpan tx_ile_pozostalo_czasu_renderingu_tsp = TimeSpan.FromMilliseconds(tx_ile_czasu_zostalo);

                p_renderingu_czas_przewidywany_label.Text = tx_ile_bedzie_trwal_lacznie_rendering_tsp.Hours.ToString("D2") + ":" + tx_ile_bedzie_trwal_lacznie_rendering_tsp.Minutes.ToString("D2") + ":" + tx_ile_bedzie_trwal_lacznie_rendering_tsp.Seconds.ToString("D2") + ":" + tx_ile_bedzie_trwal_lacznie_rendering_tsp.Milliseconds.ToString("D2");
                p_renderingu_czasu_pozostalo_label.Text = tx_ile_pozostalo_czasu_renderingu_tsp.Hours.ToString("D2") + ":" + tx_ile_pozostalo_czasu_renderingu_tsp.Minutes.ToString("D2") + ":" + tx_ile_pozostalo_czasu_renderingu_tsp.Seconds.ToString("D2") + ":" + tx_ile_pozostalo_czasu_renderingu_tsp.Milliseconds.ToString("D2");

                if (tx_ile_pozostalo_czasu_renderingu_tsp.TotalSeconds<=60 && !p_czy_odtwarzam_aktualnie_dzwiek_global && !p_co_odtworzono_za_dzwiek_global2.Equals("zostala_minuta"))
                {
                    p_czy_odtwarzam_aktualnie_dzwiek_global = true;
                    p_co_odtworzono_za_dzwiek_global2 = "zostala_minuta";
                    Task.Run(() =>
                    {
                        if (!p_wylacz_dzwiek_chk.Checked)
                        {
                            SPlayer6.PlaySync();//zostala minuta
                        }
                    });
                    p_czy_odtwarzam_aktualnie_dzwiek_global = false;
                }
                /*else if (tx_ile_pozostalo_czasu_renderingu_tsp.TotalSeconds>60)
                {
                    //p_co_odtworzono_za_dzwiek_global2 = "";
                }*/
            }

            if (!p_czy_zaczelismy_renderowac)
            {
                p_czy_zaczelismy_renderowac = true;
            }
            else if (!p_procent_prev.Equals(args.PercentComplete))
            {
                p_czas_wczesniej = DateTime.Now;
                p_procent_prev = args.PercentComplete;
            }

            p_blokada_obliczen = false;


        }

 

bool UseSelection = true

RenderArgs args = new RenderArgs();

SelectedVideoTemplate = TemplateVideoCombo.SelectedItem as RenderTemplate;

args.RenderTemplate = SelectedVideoTemplate;
args.UseSelection = UseSelection;

trackName += args.RenderTemplate.FileExtensions[0].Substring(1);
args.OutputFile = Path.Combine(p_folder_wyjsciowy.Text, trackName);


myVegas.RenderProgress += new RenderStatusEventHandler(RenderStatusEventHandlerMZ);
myVegas.RenderStarted += new EventHandler(RenderStartedHandlerMZ);

RenderStatus status = myVegas.Render(args);

if (status == RenderStatus.Complete)
{

/*I do some stuff, but it didn`t reach here, because error ocurrs whiles rendering

That's why I don't paste the whole code I`m doing here.*/

 

}

 

SelectedVideoTemplate is my customized Voukoder h265 template - mp4 file extension.

 

What can cause the problem?

Thank you for your help.

marcinzm wrote on 6/7/2022, 1:41 AM

I added some additional steps to see where the error occurs:

string p_step="";

try

{

                myVegas.RenderProgress += new RenderStatusEventHandler(RenderStatusEventHandlerMZ);
                p_step= "step21";
                myVegas.RenderStarted += new EventHandler(RenderStartedHandlerMZ);
                p_step = "step22";

                RenderStatus status = myVegas.Render(args);
                p_step = "step23";

....

}

catch (Exception eee)
{
MessageBox.Show("Show me error "+p_step+" "+eee.toString());
}

Error occurs in p_step="step22" while rendering, but not at the beginning of video rendering. I don`t know how to fix the issue :(

Do you have any idea?

The error shows step22 in error throw, but the rendering has been still continuing.

In the worst case I remove MessageBox.Show() error throw information and I will not see any error, but it is not a good idea, because it is not solving the issue.

 

jetdv wrote on 6/7/2022, 7:16 AM

What if you turn off the two event handlers that are giving your 30%, 50%, 90% warnings? If you just do a straight render with no checking, does it work then?

I'm wondering if it's really related to RenderStatusEventHandlerMZ or possibly what you're doing inside RenderStatusEventHandlerMZ?

marcinzm wrote on 6/7/2022, 7:48 AM

@jetdv I also thought about it, but the error is not throwning inside these two handlers (previously I added try and catch exception code inside these both handlers), but the error is thrown outside these two handlers, that's why I thought it is mightly not related with these handlers.
But, I added in MessageBox information about progress level when the error occurs. It lets me know if it is one of these values 30%, 50%, 90% or one minute before finish.

I need some time to test it out. I`ll reply if I know more.
Thank you for you time and help.

jetdv wrote on 6/7/2022, 8:21 AM

I'm not saying the error is happening inside that routine. I'm just wondering if that routine being called could be related. But have you checked for any errors being caused there?

marcinzm wrote on 6/7/2022, 4:36 PM

I will try to turn off the event handlers in next rendering. Now I know that the error was triggered on 28% progress level. I noticed that the error is thrown only once during a video render. I tested on 6-7 hours long video rendering and as I have written before, the error was thrown only once while rendering. The video rendering has been continuing after throwing error, that's why I decided to put the erorr message in txt file instead of MessageBox.Show() which would stop the functionality of my C# application.

Now I have only one video project content to test it out.

jetdv wrote on 6/10/2022, 7:02 AM

@marcinzm, see here:

https://www.vegascreativesoftware.info/us/forum/batch-render-exception-thrown-by-method-called--135435/

This looks very familiar! Except his says "0 C:".

marcinzm wrote on 6/11/2022, 4:02 PM

I submitted a ticket to Vegas developers, but they replied me that they will not be investigating the issue in the 3rd party C# applications which they didn`t wrote, so @edlerman and me are in that case alone. :( The error is strongly related with rendering call in C# and it is not an error caused by other than Vegas developers. In that case, this error will never be fixed by Vegas developers. I am very sad for such Vegas support approach.

marcinzm wrote on 6/16/2022, 6:20 AM

@jetdv Hello, Thank you very much for the answer!!!!!!! I think it is related in 100% with this issue!!! I got 20 minutes set. I noticed that the error ocurrs just after approximetly 20 minutes after rendering. I haven`t tested this solution, I will test it in next rendering when I have something to render. Thank you again for such good news!! Thank you!!!

marcinzm wrote on 6/18/2022, 2:07 PM

Today I have been testing the solution of increasing sleeping drive from 20 minutes to 4000 minutes. I see that the after 8 hours of rendering, the error was never thrown, so the solution works. My rendering is going to last 1 day, but I think that it would be ok.

marcinzm wrote on 6/18/2022, 2:13 PM

...But in my opinion it is still error which should be fixed by Vegas developer team, because when I render the same video from built in rendering feature in Vegas Pro 19, the exception never throws. This is exception is called only while rendering from C#, so in my opinion this bug should be fixed by Vegas Pro teams. Why this Windows sleeping duration/time drive feature doesn't impact on rendering if I render from built in rendering Vegas Pro 19 feature, but has impact on rendering feature called from C# code. The behaviours should be the same in my opinion no matter rendering I call.

jetdv wrote on 6/18/2022, 2:55 PM

@marcinzm, at least the root cause was found and a solution has also been found. Perhaps the developers will have time to look into this some time. I know they're all really busy.

marcinzm wrote on 6/18/2022, 3:30 PM

@jetdv I am a developer too. I was shocked that they replied that they will not be look into the third party application without even checking the issue. They wrote in advance that they will not cure 3rd party application. They stated that the issue is not related without even looking into the cause of the issue. I am developer too and I work a lot, I have many issues to solve, but I am not closing the tickets when the error exists. I will have to check the issue, but when I don`t have time now, I will have to look into the issue in the future, but I never close the ticket without checking the cause of the issue, because I know that the client will be angry of me. I am also a busy developer and sometimes I work 16 hours per day when there are instant tickets to solve.