Hi Darrin, Hi Paul,
I didn't know that the plugin is only loaded once and used for all instances. But when I saw the strange behavior, I guessed that this is the case.
The variables (currently 28 big arrays) are now moved to the header file and the problem was gone instantly. Initialization was of course already done in the -initWithAPIManager method, so this was already ok.
Thanks for the help!
Christoph Vonrhein
On Mar 28, 2007, at 10:48 PM, Paul Schneider wrote:
Christophe,
this sounds correct to me. Your plugin is a shared library, and there is only one instance of global variables per shared library. That's why they're global :)
If you want per-instance variables, you should make them members of your FxFilter object. There will be one instance of your object per effect instance.
On Mar 28, 2007, at 9:18 PM, Darrin Cardani wrote: You probably don't want to use global variables in this case. Can you make the variables part of the filter class instead? For example, if you had something like the following at the top of your .mm file:
float value1 = 0.0; int value2 = 0; ....
You could change your filter class to have these variables inside of it, like this:
@class MyFilter: NSObject <FxFilter> { float _value1; int _value2; ... }
Then in your implementation, you just need to initialize them in your -initWithAPIManager method, like this:
- (id) initWithAPIManager:(id)apiManager { _apiManager = apiManager;
_value1 = 0.0; _value2 = 0;
return self; }
And if they are pointers to objects, you need to release them in your -dealloc method.
You might also want to have some accessor methods:
- (float)value1 { return _value1; }
- (void)setValue1:(float)newValue { _value1 = newValue; }
- (int)value2 { return _value2; }
- (void)setValue2:(int)newValue { _value2 = newValue; }
etc.
As a general rule, it's best to avoid global variables if you can. They can cause dependencies like you're seeing, where more than 1 object wants to change their values, but it isn't safe for one when another changes the value. They can also cause problems when running in multiple threads (as your plugin does in Motion). For example, each thread may have its own copy of the global variable, which can be a problem if the same instance of the filter tries to access it from different threads.
Darrin On Mar 28, 2007, at 12:01 PM, Christoph Vonrhein wrote: Hi,
Currently I have a similar effect with a FxPlug generator I am working on. The new plugin uses a set of global variables in order to be able to use the calculated results in the next frame. If I apply the generator to Motion's timeline, everything works perfectly. When I apply it a second time, both instances interfere with each other, because Motion launches the plugin once and uses the same one for both instances.
Is there a way to find out which instance is called, so I can make the plugin use different global variables for each instance ?
regards Christoph Vonrhein
|