multiple OpenEars delegates are getting mixed up with ARC on

Home Forums OpenEars multiple OpenEars delegates are getting mixed up with ARC on

Viewing 23 posts - 1 through 23 (of 23 total)

  • Author
    Posts
  • #1021500
    gsboris
    Participant

    I have 2 view controllers (VC1 and VC2) each of them uses OpenEars for TextToSpeach.
    I also implemented delegate <OpenEarsEventsObserver> to capture -(void)fliteDidStartSpeaking{}
    -(void)fliteDidFinishSpeaking{} events.

    My problem: on VC1 everything works perfect, then I move on to VC2 and here when -(void)fliteDidStartSpeaking{} or -(void)fliteDidFinishSpeaking{} events occur it uses methods from the VC1 not the current VC2.

    I tried nil-ing OpenEars object (cannot release in ARC) on VC1 before moving to VC2, app is crashing.

    To make it work, I had to turn off ARC and manually release all OpenEars objects on VC1 before moving on to VC2.

    Is there a way to make OpenEars use proper methods without turning ARC off?

    Here is my VC1.h (that malfunctions with ARC on, to make it work: ARC=off in project build settings and release OpenEars objects in viewWillDisappear and alloc/init in viewWillAppear):

    #import <Slt/Slt.h>
    #import <OpenEars/FliteController.h>
    #import <OpenEars/OpenEarsEventsObserver.h>
    @interface VC1: UIViewController<OpenEarsEventsObserverDelegate>{
    FliteController *fliteController;
    Slt *slt;
    OpenEarsEventsObserver *openEarsEventsObserver;
    }
    @property (strong, nonatomic) FliteController *fliteController;
    @property (strong, nonatomic) Slt *slt;
    @property (strong, nonatomic) OpenEarsEventsObserver *openEarsEventsObserver;

    VC1.m

    @synthesize fliteController,slt,openEarsEventsObserver;

    -(void)say_it{
    [self.fliteController say:someTxt withVoice:self.slt];
    }
    -(void)stop_talking{
    [self.fliteController interruptTalking];
    }

    -(void)fliteDidStartSpeaking{
    //do somthing when started speaking
    }
    -(void)fliteDidFinishSpeaking{
    //do something when finished speaking
    }
    -(void)navToNextVC{//next view
    UIViewController *nextVC= [self.storyboard instantiateViewControllerWithIdentifier:@”VC2″];
    [self.navigationController pushViewController:nextVC animated:YES];
    }
    -(void)viewDidLoad{
    fliteController = [[FliteController alloc] init];
    slt = [[Slt alloc] init];
    openEarsEventsObserver = [[OpenEarsEventsObserver alloc] init];
    [openEarsEventsObserver setDelegate:self];
    }

    VC2.h amd .m is essentially the same, just different methods for fliteDidStart(Finished)Speaking.

    Thanks.

    #1021501
    Halle Winkler
    Politepix

    Welcome,

    Is the issue that only VC1 is getting callbacks, or is it possible that VC1 and VC2 are simultaneously getting callbacks from the same speech but you are reacting to the callback in VC1 first and not getting the info that VC2 is also getting the callback? The expectation is that they would both get a callback from the same speech event if they are both instantiated with OpenEarsEventsObserver delegates.

    Second question is about what is being set to nil. Did you set FliteController to nil, FliteController’s OpenEarsEventsObserver, or FliteController’s OpenEarsEventsObserver.delegate?

    #1021502
    gsboris
    Participant

    you are right, they both are called back, 1st on VC2 then on VC1.
    1st I tried nil-ing everything i.e. fliteController,slt,openEarsEventsObserver.delegate,openEarsEventsObserver then just openEarsEventsObserver.delegate in both cases app crashes.

    #1021503
    Halle Winkler
    Politepix

    It should only be necessary to set the delegate of OpenEarsEventsObserver to nil – can you just do that and show the logging output and the backtrace for the crash? To get the backtrace you’ll type “bt” when the app suspends due to the crash and you have the lldb prompt. It’s surprising that it crashes without a set delegate (versus the crash originating from something else) since the delegate methods are optional.

    #1021505
    gsboris
    Participant

    kk, will try and get back to u asap

    #1021506
    Halle Winkler
    Politepix

    OK. It’s actually working as designed that both view controllers get the events if they are both instantiated and have self as delegates. We can troubleshoot why you can’t make the first view controller no longer a delegate of the object.

    #1021507
    gsboris
    Participant

    IT IS WORKING NOW, sort of, but crashing
    it does not call VC1 now from VC2 when I just .delegate=nil on view disappear

    it is crashing while trying:
    [fliteController say:[txtArr objectAtIndex:hlIndx] withVoice:self.slt];

    here is bt:
    * thread #1: tid = 0x63a5f, 0x0003d506 AIMExplorer`feat_find_featpair + 70, queue = ‘com.apple.main-thread’, stop reason = EXC_BAD_ACCESS (code=1, address=0xe8240489)
    frame #0: 0x0003d506 AIMExplorer`feat_find_featpair + 70
    frame #1: 0x0003d9e4 AIMExplorer`feat_set + 52
    frame #2: 0x0003daed AIMExplorer`feat_set_float + 77
    frame #3: 0x0003c769 AIMExplorer`flite_feat_set_float + 57
    frame #4: 0x000e898a AIMExplorer`-[FliteController say:withVoice:] + 746
    * frame #5: 0x0000df9b AIMExplorer`-[HighlightAndReadAloudViewController say_hlTxt](self=0x0a653b50, _cmd=0x00131581) + 203 at HighlightAndReadAloudViewController.m:180
    frame #6: 0x0000ceca AIMExplorer`-[HighlightAndReadAloudViewController buttonHandler:](self=0x0a653b50, _cmd=0x00130577, sender=0x0a6dba60) + 4186 at HighlightAndReadAloudViewController.m:100
    frame #7: 0x02245880 libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 77
    frame #8: 0x00ef53b9 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 108
    frame #9: 0x00ef5345 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    frame #10: 0x00ff6bd1 UIKit`-[UIControl sendAction:to:forEvent:] + 66
    frame #11: 0x00ff6fc6 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 577
    frame #12: 0x00ff6243 UIKit`-[UIControl touchesEnded:withEvent:] + 641
    frame #13: 0x00f34ddd UIKit`-[UIWindow _sendTouchesForEvent:] + 852
    frame #14: 0x00f359d1 UIKit`-[UIWindow sendEvent:] + 1117
    frame #15: 0x00f075f2 UIKit`-[UIApplication sendEvent:] + 242
    frame #16: 0x00ef1353 UIKit`_UIApplicationHandleEventQueue + 11455
    frame #17: 0x0243d77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    frame #18: 0x0243d10b CoreFoundation`__CFRunLoopDoSources0 + 235
    frame #19: 0x0245a1ae CoreFoundation`__CFRunLoopRun + 910
    frame #20: 0x024599d3 CoreFoundation`CFRunLoopRunSpecific + 467
    frame #21: 0x024597eb CoreFoundation`CFRunLoopRunInMode + 123
    frame #22: 0x04b075ee GraphicsServices`GSEventRunModal + 192
    frame #23: 0x04b0742b GraphicsServices`GSEventRun + 104
    frame #24: 0x00ef3f9b UIKit`UIApplicationMain + 1225
    frame #25: 0x0000be3d AIMExplorer`main(argc=1, argv=0xbfffed74) + 141 at main.m:16

    #1021509
    gsboris
    Participant

    so now when I go back to VC1 it is crashing, that is

    #1021510
    Halle Winkler
    Politepix

    That looks more like it’s crashing because you aren’t using the recommended memory management from the sample app and tutorial. Can you switch over to that instead? Take a look at how FliteController is set up in the sample app and then only called as a property with self.fliteController. It’s also demonstrated step-by-step in the tutorial.

    #1021511
    gsboris
    Participant

    OK, thanks, will do that

    #1021516
    gsboris
    Participant

    well, i implemented all methods as you have them in tutorial.
    Since nil-ing delegate I does not mix controllers anymore, but it still crashes when I go back to VC1 after i used TTS on VC2 and try to make it say:
    [self.fliteController say:[txtArr objectAtIndex:hlIndx] withVoice:self.slt];

    However it does not crash if I make it say on VC1, go to VC2 and return to VC1 and make it say.
    It seems to crash if I make it say on VC2 and return to VC1 and try make it say again.

    here is my methods:

    -(void)viewWillAppear:(BOOL)animated{
    [self.openEarsEventsObserver setDelegate:self];
    }
    -(void)viewWillDisappear:(BOOL)animated{
    self.openEarsEventsObserver.delegate=nil;
    }
    – (OpenEarsEventsObserver *)openEarsEventsObserver {
    if (openEarsEventsObserver == nil) {
    openEarsEventsObserver = [[OpenEarsEventsObserver alloc] init];
    }
    return openEarsEventsObserver;
    }
    – (FliteController *)fliteController {
    if (fliteController == nil) {fliteController = [[FliteController alloc] init];}
    return fliteController;
    }
    – (Slt *)slt {
    if (slt == nil) {slt = [[Slt alloc] init];}
    return slt;
    }

    here is bt:
    * thread #1: tid = 0x93e1b, 0x0321a3f4 libsystem_c.dylib`strcmp + 84, queue = ‘com.apple.main-thread’, stop reason = EXC_BAD_ACCESS (code=2, address=0x8)
    frame #0: 0x0321a3f4 libsystem_c.dylib`strcmp + 84
    frame #1: 0x0003d504 AIMExplorer`feat_find_featpair + 84
    frame #2: 0x0003d9d4 AIMExplorer`feat_set + 52
    frame #3: 0x0003dadd AIMExplorer`feat_set_float + 77
    frame #4: 0x0003c759 AIMExplorer`flite_feat_set_float + 57
    frame #5: 0x000e897a AIMExplorer`-[FliteController say:withVoice:] + 746
    * frame #6: 0x0000dd1f AIMExplorer`-[HighlightAndReadAloudViewController say_hlTxt](self=0x0a3338a0, _cmd=0x00131583) + 223 at HighlightAndReadAloudViewController.m:183
    frame #7: 0x0000cc3a AIMExplorer`-[HighlightAndReadAloudViewController buttonHandler:](self=0x0a3338a0, _cmd=0x00130579, sender=0x0a334eb0) + 4186 at HighlightAndReadAloudViewController.m:100
    frame #8: 0x02245880 libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 77
    frame #9: 0x00ef53b9 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 108
    frame #10: 0x00ef5345 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    frame #11: 0x00ff6bd1 UIKit`-[UIControl sendAction:to:forEvent:] + 66
    frame #12: 0x00ff6fc6 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 577
    frame #13: 0x00ff6243 UIKit`-[UIControl touchesEnded:withEvent:] + 641
    frame #14: 0x00f34ddd UIKit`-[UIWindow _sendTouchesForEvent:] + 852
    frame #15: 0x00f359d1 UIKit`-[UIWindow sendEvent:] + 1117
    frame #16: 0x00f075f2 UIKit`-[UIApplication sendEvent:] + 242
    frame #17: 0x00ef1353 UIKit`_UIApplicationHandleEventQueue + 11455
    frame #18: 0x0243d77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    frame #19: 0x0243d10b CoreFoundation`__CFRunLoopDoSources0 + 235
    frame #20: 0x0245a1ae CoreFoundation`__CFRunLoopRun + 910
    frame #21: 0x024599d3 CoreFoundation`CFRunLoopRunSpecific + 467
    frame #22: 0x024597eb CoreFoundation`CFRunLoopRunInMode + 123
    frame #23: 0x04b075ee GraphicsServices`GSEventRunModal + 192
    frame #24: 0x04b0742b GraphicsServices`GSEventRun + 104
    frame #25: 0x00ef3f9b UIKit`UIApplicationMain + 1225
    frame #26: 0x0000bbad AIMExplorer`main(argc=1, argv=0xbfffed74) + 141 at main.m:16

    #1021517
    Halle Winkler
    Politepix

    These really seem like issues with the FliteController implementation in each view controller. The crash is very much a crash of FliteController, and the OpenEarsEventsObserver is a separate object (with very strong separation between the two objects in question) and there’s no reason for it to care whether it has a set delegate and in which view controller it is set or not set.

    I think we actually need to just troubleshoot why your FliteController instance doesn’t work quite right. I would shut off OpenEarsEventsObserver entirely (don’t instantiate it, don’t make anything a delegate of it) and see if this crash replicates independently without anything going on but FliteController.

    #1021518
    gsboris
    Participant

    Could it be simulator issues? I am going to test it on real device first.

    #1021519
    Halle Winkler
    Politepix

    It’s always much better to test on a real device, but I think step one is to identify the actual issue, so it would be good to remove OpenEarsEventsObserver in order to verify that this FliteController crash isn’t related to it.

    #1021520
    gsboris
    Participant

    well, my app is heavily relied on the observer though. It is TTS with word/sentence/paragraph highlights, I really need that observer to discern when and what to highlight. I will try something, perhaps w/o highlights for now. will get back to you. Thank you very much for your patience and expertise.

    #1021521
    Halle Winkler
    Politepix

    Don’t worry, we aren’t trying to remove the functionality of OpenEarsEventsObserver from your app permanently as some kind of workaround for the issue, we’re just starting to troubleshoot the crash you’re reporting by first finding out what it is/isn’t connected to, in order to fix the real issue (I don’t think it has to do with OpenEarsEventsObserver or ARC – to me it looks like it’s either an issue with FliteController or it’s Slt not being instantiated any more when it’s needed by FliteController).

    So step one is to rule OpenEarsEventsObserver out as the problem by turning it off and seeing if the crash still happens. If the crashing behavior is the same, you can turn OpenEarsEventsObserver back on but stop troubleshooting it, because that suggests that the issue is independent of OpenEarsEventsObserver and you can spend the attention on FliteController. If the crash does not occur when OpenEarsEventsObserver is off, that suggests that it is related to OpenEarsEventsObserver. Both outcomes would tell us more about what is going on when your app is having this crash.

    #1021522
    gsboris
    Participant

    i turned off observer – same issue.
    i played with different voices: if I use slt on VC1 and rms on VC2 – it does not crash, i can go back and forth and it is fine!
    Using same voice on both causes that. As soon as I use the same voice on VC2 and go back to VC1 it crashes while trying to say.

    #1021523
    Halle Winkler
    Politepix

    OK, that is useful info. I think this is just about the voices, maybe something about shared resources with the voices. Is Slt lazy-instantiated in both view controllers and only called with self.slt like in the tutorial?

    #1021524
    gsboris
    Participant

    OK, I nil-ed voices before leaving the view and it cured it. does not crash anymore.

    And, yes it is called with self.slt as you have in tutorial.

    #1021526
    gsboris
    Participant

    TY for guiding me through this. Will check this same issue on real device, will see if it is the same and let you know. Best regards.

    #1021527
    Halle Winkler
    Politepix

    OK, I nil-ed voices before leaving the view and it cured it. does not crash anymore.

    I see, that’s quite interesting and may be a bug for me to check out. Glad the issue is clearing up, and let me know how it goes with the device.

    #1021543
    gsboris
    Participant

    Hi Halle,
    Unfortunately, the same problem persists on the device too. I checked it on iPad2 iOS7.1.1 app crashes if it tries to RE-USE the voice on the 1st VC that has been used on 2nd VC. Nil-ing voice obj, when leaving to 2nd VC, seems to solve this issue, cause it forces it to reinit the voice, when you return to work on the 1st VC.
    Boris

    #1021544
    Halle Winkler
    Politepix

    OK, just go ahead with setting the voice to nil and I’ll take a look at the underlying issue when there is time.

Viewing 23 posts - 1 through 23 (of 23 total)
  • You must be logged in to reply to this topic.