This project has moved. For the latest updates, please go here.

Handle is not initialized.

Mar 11, 2009 at 1:39 AM
Edited Mar 12, 2009 at 3:44 AM
Hello.

I use a x64 system but I need to run your library as x86. I changed all projects so that platform target is x86 and they compile fine.
Then I compiled the "host" example and it starts correctly. So there are no platform mismatches between all the assemblies.

Now if I try to load a plug-in, the library is loaded, the main is found but when your code calls

_pEffect = pluginMain(&DispatchCallback);

an exception is thrown of type InvalidOperationException with the message "Handle is not initialized.".

I don't know if the platform is the root of the problem but I mentioned it because it's the only change to your projects that I made.

Can you help me to find the cause of this issue?

Thanks!
Coordinator
Mar 11, 2009 at 6:53 AM
Hi,

What plugin do you load? Is it one of the samples or...?
Could you email me the plugin (obiwanjacobi at hotmail dot com)?

Could you also post the complete error with call stack?
Mar 12, 2009 at 3:37 AM
Edited Mar 12, 2009 at 8:36 AM
Hello. I emailed more info about the plugin

Full exception information:

System.InvalidOperationException was unhandled
  Message="Handle is not initialized."
  Source="mscorlib"
  StackTrace:
       at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
       at ?A0xaa2e6e32.DispatchCallback(AEffect* pEffect, Int32 opcode, Int32 index, Int32 value, Void* ptr, Single opt) in d:\vst.net\svn\source\code\jacobi.vst.interop\host\vstunmanagedplugincontext.cpp:line 190
       at Jacobi.Vst.Interop.Host.VstUnmanagedPluginContext.Initialize(String pluginPath) in d:\vst.net\svn\source\code\jacobi.vst.interop\host\vstunmanagedplugincontext.cpp:line 101
       at Jacobi.Vst.Interop.Host.VstPluginContext.InitializeUnmanaged(String pluginPath, IVstHostCommandStub hostCmdStub) in d:\vst.net\svn\source\code\jacobi.vst.interop\host\vstplugincontext.cpp:line 88
       at Jacobi.Vst.Interop.Host.VstPluginContext.Create(String pluginPath, IVstHostCommandStub hostCmdStub) in d:\vst.net\svn\source\code\jacobi.vst.interop\host\vstplugincontext.cpp:line 33
       at Jacobi.Vst.Samples.Host.MainForm.OpenPlugin(String pluginPath) in D:\VST.NET\svn\Source\Samples\Jacobi.Vst.Samples.Host\MainForm.cs:line 46
       at Jacobi.Vst.Samples.Host.MainForm.AddBtn_Click(Object sender, EventArgs e) in D:\VST.NET\svn\Source\Samples\Jacobi.Vst.Samples.Host\MainForm.cs:line 117
       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.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(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(Int32 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.Application.Run(Form mainForm)
       at Jacobi.Vst.Samples.Host.Program.Main() in D:\VST.NET\svn\Source\Samples\Jacobi.Vst.Samples.Host\Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:




Locals:

        pluginPath    "C:\Program Files (x86)\Steinberg\VstPlugins\TheCoolPlugIn.dll"    System::String^
-        hostCmdStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
-        [Jacobi::Vst::Samples::Host::HostCommandStub^]    0x02751d8c    Jacobi::Vst::Samples::Host::HostCommandStub^
        System::Object^    0x02751d8c    System::Object^
-        <PluginContext>k__BackingField    0x02752718    Jacobi::Vst::Core::Host::IVstPluginContext^
+        [Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^]    0x02752718 { _hLib=<undefined value> _pEffect=<undefined value> ...}    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
+        HostCommandStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
        PluginCommandStub    <undefined value>    Jacobi::Vst::Core::Host::IVstPluginCommandStub^
        PluginInfo    <undefined value>    Jacobi::Vst::Core::Plugin::VstPluginInfo^
-        PluginCalled    0x02751d9c    System::EventHandler<Jacobi::Vst::Samples::Host::PluginCalledEventArgs^>^
+        [System::EventHandler<Jacobi::Vst::Samples::Host::PluginCalledEventArgs^>^]    0x02751d9c    System::EventHandler<Jacobi::Vst::Samples::Host::PluginCalledEventArgs^>^
+        System::MulticastDelegate^    0x02751d9c { _invocationList=<undefined value> _invocationCount=0 }    System::MulticastDelegate^
-        PluginContext    0x02752718    Jacobi::Vst::Core::Host::IVstPluginContext^
+        [Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^]    0x02752718 { _hLib=<undefined value> _pEffect=<undefined value> ...}    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
+        HostCommandStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
        PluginCommandStub    <undefined value>    Jacobi::Vst::Core::Host::IVstPluginCommandStub^
        PluginInfo    <undefined value>    Jacobi::Vst::Core::Plugin::VstPluginInfo^
-        PluginContext    0x02752718    Jacobi::Vst::Core::Host::IVstPluginContext^
-        [Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^]    0x02752718 { _hLib=<undefined value> _pEffect=<undefined value> ...}    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
+        Jacobi::Vst::Interop::Host::VstPluginContext^    0x02752718    Jacobi::Vst::Interop::Host::VstPluginContext^
        <backing_store>LoadingPlugin    <undefined value>    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
+        HostCommandProxy    0x02752774 { _hostCmdStub=0x02751d8c }    Jacobi::Vst::Interop::Host::VstHostCommandProxy^
        LoadingPlugin    <undefined value>    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
        _hLib    <undefined value>    HINSTANCE__*
+        _hostCmdProxy    0x02752774 { _hostCmdStub=0x02751d8c }    Jacobi::Vst::Interop::Host::VstHostCommandProxy^
        _pEffect    <undefined value>    AEffect*
-        HostCommandStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
+        [Jacobi::Vst::Samples::Host::HostCommandStub^]    0x02751d8c    Jacobi::Vst::Samples::Host::HostCommandStub^
+        PluginContext    0x02752718    Jacobi::Vst::Core::Host::IVstPluginContext^
        PluginCommandStub    <undefined value>    Jacobi::Vst::Core::Host::IVstPluginCommandStub^
        PluginInfo    <undefined value>    Jacobi::Vst::Core::Plugin::VstPluginInfo^
-        pluginCtx    0x02752718 { _hLib=<undefined value> _pEffect=<undefined value> ...}    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
-        Jacobi::Vst::Interop::Host::VstPluginContext^    0x02752718    Jacobi::Vst::Interop::Host::VstPluginContext^
        System::Object^    0x02752718    System::Object^
        <backing_store>PropertyChanged    <undefined value>    System::ComponentModel::PropertyChangedEventHandler^
+        HostCommandStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
        PluginCommandStub    <undefined value>    Jacobi::Vst::Core::Host::IVstPluginCommandStub^
        PluginInfo    <undefined value>    Jacobi::Vst::Core::Plugin::VstPluginInfo^
+        _hostCmdStub    0x02751d8c    Jacobi::Vst::Core::Host::IVstHostCommandStub^
        _pluginCmdStub    <undefined value>    Jacobi::Vst::Core::Host::IVstPluginCommandStub^
        _pluginInfo    <undefined value>    Jacobi::Vst::Core::Plugin::VstPluginInfo^
+        _props    0x02752740    System::Collections::Generic::Dictionary<System::String^, System::Object^>^
        <backing_store>LoadingPlugin    <undefined value>    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
+        HostCommandProxy    0x02752774 { _hostCmdStub=0x02751d8c }    Jacobi::Vst::Interop::Host::VstHostCommandProxy^
        LoadingPlugin    <undefined value>    Jacobi::Vst::Interop::Host::VstUnmanagedPluginContext^
        _hLib    <undefined value>    HINSTANCE__*
+        _hostCmdProxy    0x02752774 { _hostCmdStub=0x02751d8c }    Jacobi::Vst::Interop::Host::VstHostCommandProxy^
        _pEffect    <undefined value>    AEffect*

I hope it's readable...

Coordinator
Mar 12, 2009 at 6:04 AM
Edited Mar 12, 2009 at 6:09 AM

Thanx for the info. I think I can tell what the problem is just from looking at the callstack but I will test it with the plugin info you sent me.
I see you are using the latest code! ;-)
I think the problem is when the Plugin calls back to the Host during initialization of the Plugin (VSTPluginMain method). The "DispatchCallback" is a static method that receives Plugin-to-Host calls and retrieves the VstPluginContext instance from a reserved field in the AEffect structure. I just need to check that field for NULL and the code will fallback to the (internal) static LoadingPlugin property that was created just for that purpose.

Good catch, thanx!

Coordinator
Mar 12, 2009 at 10:35 AM
I didn't have time to test it yet but I've checked in a fix (and a lot of other stuff).

You could try it, if you feel adventurous ;-)
Mar 12, 2009 at 10:54 PM
The plug-in is added but when I push the "View" button to open the editor it causes a "heap corruption detected" dialog from the C++ debug library. :(
Coordinator
Mar 13, 2009 at 8:27 PM
I tested it and it appears that the plugin returns a string that is too large for a parameter name. The max length of a parameter name is 8 characters (as defined by kVstMaxParamStrLen in the VST SDK) and it returns the string "Global: Bypass" for the first parameter name (index=0). Too me, that is a bug in the plugin (it is just reported with the host.exe because the allocated the memory that was overrun)... :-(

To see for yourself open up the Host sample application and set a breakpoint in the FillParameterList method in the PluginForm.cs. You'll see it crash after the first call to GetParameterName(i);

I did enlarge the parameter-related string buffers to allow 64 chars.
It did also bring to light another bug that was in the VstPluginContext.Dispose resource cleanup.
I did a new checkin with the fixes.

Hope they work for you.
Mar 13, 2009 at 11:42 PM
Yes, now the demo program works correctly with that plugin too. Thanks!