Skip to main content
May 7, 2009
Question

About "FIXUP_VTABLE" in CS4

  • May 7, 2009
  • 1 reply
  • 1297 views

In Cs4 sdk,there is a  VTableSupport.hpp :

// If your plugin has a C++ object attached to it's globals, and if
// the class of that object has virtual functions, those functions
// will not work after the plugin is unloaded and then reloaded.
//
// The following macro (FIXUP_VTABLE) can be used to provide a means
// of restoring the virtual function table of a globally-persistent
// C++ object by calling FixupVTable() prior to the use of any of
// the object's virtual functions after a reload.
//
// Here is how you might use the macro:

I found  there is some bug about (FIXUP_VTABLE).  now ,let 't see samplecode  "ADMNonModalDialog":

ADMNonModalDialog::ADMNonModalDialog(SPPluginRef pluginRef) : BaseADMDialog()
{
fAccessRef = NULL;
int options = 0;
this->pluginRef=pluginRef;

// Create the Non-modal dialog. This does not necessarily show the dialog on
// the screen. If the dialog was hidden at last shutdown, it will not be shown
// until sADMDialog->Show() is called.
// Note: the init proc - Init, will be called immediately following Create()
this->Create(pluginRef, "ADMNonModalDialog", kADMNonModalDialogID, kADMTabbedFloatingDialogStyle, options);

}

ASErr ADMNonModalDialogPlugin::GoMenuItem(AIMenuMessage* message)
{
ASErr error = kNoErr;

if (message->menuItem == this->fShowADMNonModalDialog) {
  if (this->fADMNonModalDialog) {
   ASBoolean visible = this->fADMNonModalDialog->IsVisible();
   this->fADMNonModalDialog->Show(!visible);
    }
}
else if (message->menuItem == this->fAboutPluginMenu) {
  // Pop this plug-in's about box.
  SDKAboutPluginsHelper aboutPluginsHelper;
  aboutPluginsHelper.PopAboutBox(message, "About ADMNonModalDialog", kSDKDefAboutSDKCompanyPluginsAlertString);
}

if (error)
  goto error;

error:
return error;

}

I change these two function to:

ADMNonModalDialog::ADMNonModalDialog(SPPluginRef pluginRef) : BaseADMDialog()
{
fAccessRef = NULL;
int options = 0;
this->pluginRef=pluginRef;

// Create the Non-modal dialog. This does not necessarily show the dialog on
// the screen. If the dialog was hidden at last shutdown, it will not be shown
// until sADMDialog->Show() is called.
// Note: the init proc - Init, will be called immediately following Create()

//this->Create(pluginRef, "ADMNonModalDialog", kADMNonModalDialogID, kADMTabbedFloatingDialogStyle, options);

// I  want to create a modal dialog

}

ASErr ADMNonModalDialogPlugin::GoMenuItem(AIMenuMessage* message)
{
ASErr error = kNoErr;

if (message->menuItem == this->fShowADMNonModalDialog) {
  if (this->fADMNonModalDialog) {


  //ASBoolean visible = this->fADMNonModalDialog->IsVisible();
   //this->fADMNonModalDialog->Show(!visible);

  this->fADMNonModalDialog->Modal(this->fPluginRef,"ADMModalDialog",kADMNonModalDialogID);

//when debug to here,program dead.

//int BaseADMDialog::Modal(SPPluginRef pluginRef, char* name, int dialogID, ADMDialogStyle style, int options)

//is a virtual function
  

  }
}
else if (message->menuItem == this->fAboutPluginMenu) {
  // Pop this plug-in's about box.
  SDKAboutPluginsHelper aboutPluginsHelper;
  aboutPluginsHelper.PopAboutBox(message, "About ADMNonModalDialog", kSDKDefAboutSDKCompanyPluginsAlertString);
}

if (error)
  goto error;

error:
return error;

}

This topic has been closed for replies.

1 reply

A. Patterson
Inspiring
May 7, 2009

Honestly? We found that the whole broken Vtable thing wasn't worth bothering with. The Vtable only gets broken when the plugin is unloaded & reloaded, so our solution was just to make sure we never get unloaded.

If you want to prevent your plugin from ever unloading, juust acquire it with SPAccess::AcquirePlugin(). Use SPAccess::ReleasePlugin() when you're done and ready to quit. That will mean your Vtable never gets fubar'd. If you're worried about memory footprint, don't. Frankly, I think the load/unload nature of plugins is kind of outdated; a throwback to when memory was far scarcer. I doubt the typical plugin is more than a drop in the sea of a user's RAM, so they won't notice at all if you don't unload & reload constantly.

May 7, 2009

Oh,  Thanks, A. Patterson