[Inject] doesn't work on one PC

iamable's Avatar

iamable

27 Aug, 2014 02:29 PM

Hey com,

I have a problem: The Injection from robotlegs doesn't work on one single PC.
On my developer PC it is working on another PC it doesn't.
Can you tell me why? It's completely the same compilied .exe.

To explain the structure: I have a service for playing sounds. this service is mapped as a singleton and instatiated from the context.
Further I have several Commands triggering the playSound() method from the service. The service is injected into the commands.
for every command there is a mapping to an event within the context.

With some debugging output I found out on my PC (everything works fine) the service is instatiated once and the command is calling playSound().
On the other PC (where it doesn't work) the service is instatiated once at the beginning and every command is instatiating the service again and not calling playSound()

How could this be?

Here is the important part of the code:

conext:
override public function startup():void
{
//************************Services********************* injector.mapSingleton(SoundMachine);

        //************************Models*********************
        injector.mapSingleton(SoundModel);



        //*****************Commands**************************

        //Sound Commands
        commandMap.mapEvent(VehicleModelEvent.ACTIVE_MODE_CHANGED, CAChanged);
        commandMap.mapEvent(SafetyCorridorModelEvent.ESCALATION_LEVEL_CHANGED, EscLevelChanged);
        commandMap.mapEvent(SafetyCorridorModelEvent.TRANSITION_WARNING_CHANGED, EscLevelChanged);
        commandMap.mapEvent(SoundEvent.PLAY_PROMPT, PlayPrompt);


        /********************************************************
         ********************** Views ***************************
         ********************************************************/

        //Main View
        mediatorMap.mapView(MainView, MainViewMediator);

        contextView.addChild(new MainView());
        contextView.stage.addEventListener(KeyboardEvent.KEY_DOWN, dispatchEvent);

        var soundMachine:SoundMachine = injector.getInstance(SoundMachine);

        dispatchEvent(new AmbientEvent(AmbientEvent.STARTUP));

}

command:
public class EscLevelChanged extends Command
{
[Inject] public var soundMachine : SoundMachine;

    public function EscLevelChanged()
    {
    }

    override public function execute():void
    {
        soundMachine.playStaticSound(soundMachine.WARNING_LEVEL2);
    }
}</code>

service:
[PostConstruct]
public function init() : void { vehicleModel.debuggerMessage = "sound initialisiert";

        possibleSoundTimer.addEventListener(TimerEvent.TIMER_COMPLETE, setPossibleSendingFree);

        var relativeFile:File = File.applicationDirectory;
        relativeFile = relativeFile.resolvePath("SoundBank");
        var nativePath:String = relativeFile.nativePath;
        nativePath = nativePath.replace(/\\/g, "\\\\");
        nativePath += "\\";

        SoundEngineExt = new SoundEngine();
        SoundEngineExt.setBasePath( nativePath );

        SoundEngineExt.loadBank( "Init" );

        SoundEngineExt.registerGameObj(gO_static, "static");
        SoundEngineExt.registerGameObj(gO_dynamic_comet, "dynamic");
        SoundEngineExt.registerGameObj(gO_dynamic_obstacle, "dynamic");
        SoundEngineExt.registerGameObj(gO_dynamic_warning, "dynamic");
    }

    public function playStaticSound(identifier:String):void
    {
        vehicleModel.debuggerMessage = "play sound";

        SoundEngineExt.postEvent(identifier, gO_static);
        SoundEngineExt.renderAudio();
    }</code>
  1. 1 Posted by iamable on 27 Aug, 2014 02:54 PM

    iamable's Avatar

    In addition here the comparison of the debugging outputs

    PC1 (working)
    sound initialisiert
    play sound
    play sound
    play sound
    play sound
    play sound

    PC2 (not working)
    sound initialisiert
    sound initialisiert
    sound initialisiert
    sound initialisiert
    sound initialisiert
    sound initialisiert

  2. Support Staff 2 Posted by Ondina D.F. on 27 Aug, 2014 03:10 PM

    Ondina D.F.'s Avatar

    Hey,

    • First thing to clear up: are you compiling against the source of robotlegs? If so, have you added the compiling arguments needed? Like so:

    -keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct

    Have you tried to run a release build of your application on the computer where it was working? Or was it a debug version that worked?

    • Then, are you keeping a reference to your context? Can you post the code where you initialize your context. What is the scope of the variable holding the IContext?

    • Are you using modules in your app? Is everything ok with the ApplicationDomain?

    Please answer these questions, so we can narrow down the issue.

    Ondina

  3. 3 Posted by iamable on 27 Aug, 2014 03:18 PM

    iamable's Avatar
    1. no I am using the .swc library. and I didn't added the compiling arguments

    2. yes I have the compilied release running on my machine.

    3.package
    { [SWF(frameRate="30", height="540", width="1440",backgroundColor="#000000")]

    public class Main extends Sprite
    {
        private var mainContext:MainContext;
    
        public function Main()
        {
            mainContext = new MainContext(this);
        }
    }
    

    }

    1. no I don't think I am using modules. How do you define modules?
      But everything seems fine besides the sound. everything is displayed and working pretty well
  4. Support Staff 4 Posted by Ondina D.F. on 27 Aug, 2014 03:40 PM

    Ondina D.F.'s Avatar

    In this case I think of race conditions of some sort.
    Or, maybe the PostConstruct method is the culprit.

    On the other PC (where it doesn't work) the service is instatiated once at the beginning and every command is instatiating the service again and not calling playSound()

    Do you mean that init() is called every time?

    Or, is the service null in your command?

    If you comment out this line:
    var soundMachine:SoundMachine = injector.getInstance(SoundMachine);

    and you try to run your app again on the 'good' PC, does it work?

    Would it be possible to attach the app ( making the discussion private for the time being) , so I can take a look at it?

  5. 5 Posted by iamable on 27 Aug, 2014 04:00 PM

    iamable's Avatar

    yes the init() is called every time.

    before I tried without the line: var soundMachine:SoundMachine = injector.getInstance(SoundMachine);
    --> same problem. (on one PC working, on the other not)

    I will try without [PostConstruct] and calling init() at first instance in context

    Unfortunately attaching the app is not possible.

  6. Support Staff 6 Posted by Ondina D.F. on 27 Aug, 2014 04:03 PM

    Ondina D.F.'s Avatar

    You have this in your service class:
    possibleSoundTimer.addEventListener(TimerEvent.TIMER_COMPLETE, setPossibleSendingFree);

    I can't see how you use the timer, but maybe it is initiating an async process which may be the cause of race conditions?

    Or this:
    SoundEngineExt.loadBank( "Init" );
    Is it an async process?

  7. Support Staff 7 Posted by Ondina D.F. on 27 Aug, 2014 04:12 PM

    Ondina D.F.'s Avatar

    So, the Service gets injected into your commands.

    Try to replace your SoundMachine with a very simple class, having just the init() and a playStaticSound methods, that do nothing (just having trace statements) and see what happens. If it works, then you'll have to refactor your service class...

  8. Support Staff 8 Posted by Ondina D.F. on 27 Aug, 2014 04:21 PM

    Ondina D.F.'s Avatar

    Also, is it possible to compile your application on the 'bad' PC? If yes, does it work?

    Is the 'good' PC slower or faster than the other one? Do you have the same FlashPlayer installed?

    Is it a desktop or a browser application?

  9. 9 Posted by iamable on 27 Aug, 2014 05:57 PM

    iamable's Avatar

    OK I figured out whats going wrong here.
    Within the service I am triggering some loading from a native extension and I am getting the error #3500. Some googling tells me within that extension is missing a method.
    But I don't understand why this problem is only on one machine.
    I will ask the supplier of the ANE whats going wrong here.
    Do you know anything about native extensions? Are there any methods which have to be implemented in every native extension?

    But OK. Like expected: robotlegs is running perfectly ;-)
    With calling init() once in context the calls to play sound are working too.
    Only [PostConstruct] seems to be buggy.

    Thank you :-)

  10. Support Staff 10 Posted by Ondina D.F. on 28 Aug, 2014 08:59 AM

    Ondina D.F.'s Avatar

    You're welcome!

    I'm afraid I can't help you with ANE.

    I wish you luck in finding a solution :)

  11. Ondina D.F. closed this discussion on 28 Aug, 2014 08:59 AM.

  12. creynders re-opened this discussion on 28 Aug, 2014 10:17 AM

  13. Support Staff 11 Posted by creynders on 28 Aug, 2014 10:17 AM

    creynders's Avatar

    With calling init() once in context the calls to play sound are working too. Only [PostConstruct] seems to be buggy.

    Not saying it's impossible there's a bug there, but I'm pretty certain the repeated calls are due to reinstantiating the service. Could it be the service instance is tore down due to the error thrown by the ANE? Hence if the service is declared as a dependency in two other components it will be reinstantiated twice.

  14. Support Staff 12 Posted by creynders on 28 Aug, 2014 10:18 AM

    creynders's Avatar

    And regarding the ANE: probably the error thrown has something to do with a failing connection to the sound card?

  15. 13 Posted by iamable on 28 Aug, 2014 10:26 AM

    iamable's Avatar

    "Could it be the service instance is tore down due to the error thrown by the ANE?"

    I don't know what happens when a service throws an error
    this is the init function

    public function init() : void
    { vehicleModel.debuggerMessage = "sound wird initialisiert";

            possibleSoundTimer.addEventListener(TimerEvent.TIMER_COMPLETE, setPossibleSendingFree);
    
            var relativeFile:File = File.applicationDirectory;
            relativeFile = relativeFile.resolvePath("SoundBank");
            var nativePath:String = relativeFile.nativePath;
            nativePath = nativePath.replace(/\\/g, "\\\\");
            nativePath += "\\\\";
    
            vehicleModel.debuggerMessage = nativePath;
    
            try
            {
                SoundEngineExt = new SoundEngine();
                SoundEngineExt.setBasePath( nativePath );
    
                SoundEngineExt.loadBank( "Init" );
                SoundEngineExt.loadBank( "Proreta3" );
    
                SoundEngineExt.registerGameObj(gO_static, "static");
                SoundEngineExt.registerGameObj(gO_dynamic_comet, "dynamic");
                SoundEngineExt.registerGameObj(gO_dynamic_obstacle, "dynamic");
                SoundEngineExt.registerGameObj(gO_dynamic_warning, "dynamic");
            }
            catch(e:Error)
            {
                vehicleModel.debuggerMessage = e.name;
                vehicleModel.debuggerMessage = e.message;
                vehicleModel.debuggerMessage = e.getStackTrace();
            }
    
        }
    

    "And regarding the ANE: probably the error thrown has something to do with a failing connection to the sound card?"

    Hmm maybe. But Windows sounds are playing

  16. 14 Posted by iamable on 28 Aug, 2014 12:39 PM

    iamable's Avatar

    OK we fixed the issue.
    It was a problem within the native extension while setting the base path.

    Thank you so much for the support.
    Very good forum here

  17. Ondina D.F. closed this discussion on 29 Oct, 2014 11:41 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac