Next: , Previous: Basic Features for Plugins, Up: GUI Plugin Interface

10.4.2 How to Avoid Plugin Problems

At present, the user can load a plugin several times, which could cause some problems. For example, you store the plugin menu ID in a static variable and after another load of the plugin, the value of the variable is changed. When unregistering any of the plugin instances, the same ID is used and the old value is forgotten – you unregister one plugin instance several times and the other ones remain registered.

When adding a command “manually” into the Command structure, another problem can occur: the Command Structure fills the next and parent pointers in the added command so that it is linked in the internal structures. After adding the same command several times, the pointer structure is broken and the Command Structure gets confused and might get lost in an infinite cycle.

Thus, you should prevent the user from causing problems by loading your plugin multiple times. A simple example how to do that is:

     int my_menu_id = -1;
     int stopped;
     u32 plugin_start(void)
         if (my_menu_id != -1)
             return 0;
         my_menu_id = plugin_menu_register("My plugin");
         // register some functions, ...
         return MY_PLUGIN_FLAGS;
     void plugin_stop(void)
         if (stopped)
         stopped = 1;

You should also try to avoid collisions of variable names with other plugins' variables, for example, by prefixing the names with the name of your plugin.