removeAllTargets doesn't seem to reset texture index on blend filters
Well, this started out as another "problem" until I realized there was something else going on, potentially in the core library. When I removeAllTargets on a blend filter before giving it new inputs, the addTarget method isn't starting at 0 again, rather it tries to add them at index 1.
I think the problem might be that GPUImageTwoInputFilter isn't resetting hasSetFirstTexture properly. Everything works fine if I specify the index as 0 or 1 when adding my sources to the filter,
or
if I first set the filter's target to the outputView before adding the source targets to the filter. In other words, if I try [filter addTarget:output] first, it works with [source addTarget:filter], if [filter addTarget...] comes after, it won't.
I know it looks a little confusing at first, but I think the clue is how the twoInputFilter deals with RemoveTargets - it doesn't do it 100% quite right; the input count isn't reset.
I think you're right. hasSetFirstTexture should be set to NO when removeAllTargets is called. Simple enough of a fix; I'll add it to my fork so it'll be included in my next pull request.
I'm also wondering if hasReceivedFirstFrame and hasReceivedSecondFrame should be set back to NO, but my initial thoughts are no, they shouldn't be.
@TomCorwine Thanks!
Actually, it looks like this is already being done:
- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex;
{
if (textureIndex == 0)
{
[super setInputSize:newSize atIndex:textureIndex];
if (CGSizeEqualToSize(newSize, CGSizeZero))
{
hasSetFirstTexture = NO;
}
}
}
If I read your post correctly, it seems you are calling removeAllTargets on blend filter before adding new inputs to it? removeAllTargets would only remove the targets to the blend filter. You would have to call removeAllTargets on whatever comes before the blend filter.
I'm using a Chroma Key blend filter, which has two inputs. When I remove the second input and add it again, everything works. If I remove the first input and add it again, everything breaks.
I was able to fix it with this simple code, based on input from your discussion:
[self.sourcePicture removeAllTargets];
[self.experimentalfilter removeAllTargets];
// WARNING, Accesses protected iVars
if( self.chromaKey->filterSourceTexture == 0 )
{
self.chromaKey->hasSetFirstTexture = NO;
}
[self.experimentalfilter addTarget:self.chromaKey];
[self.sourcePicture addTarget:self.chromaKey];
Thanks for your help! I'm not sure how to make this fix more generic, but for my purposes this works great. I just added @public to the header files so I could access those properties.