Having an issue where signals with N commands bound get executed N times in Unity

43 views
Skip to first unread message

Jason Araujo

unread,
Mar 7, 2018, 11:27:35 PM3/7/18
to StrangeIoC
Hey there,

I'm having a particular issue that I'm having a hard time with.
I am using Unity3d and just starting to build up the system for a project. I'm in the early stages of development, so there aren't a lot of places for things to go wrong (yet).

I have signals bound to several commands, and I'm finding that when I dispatch any signal with multiple commands bound, all of those commands get executed multiple times, exactly as many times as there are commands bound

So, for example, one signal binding looks like this:

commandBinder.Bind<LoadSceneSignal>().InSequence()
               
.To<DispatchSignalCommand<SceneWillLoadSignal>>()
               
.To<LoadSceneCommand>()
               
.To<WaitForSignalCommand<OnSceneLoadedSignal>>();

In the above case, Dispatching the LoadSceneSignal will result in the 3 commands getting executed 3 times each.

If I remove the last command, then the two remaining commands, on signal dispatch, will get called 2 times each.
The same occurs if I add commands on to the end of this binding.

One thing to note: If I dispatch a signal from within the Context Laucnh() method, the commands get executed one time only, as expected.

Has anyone seen this before, or have an Idea where I might look to begin to debug this?
I've verified that the call to dispatch that signal happens only once, so there aren't multiple signals being sent.

thank you in advance for any help.
i recently worked for a company that heavily relied on Strange for a project, and I really got to love it, so I'm hoping to make this work so that I can continue building my current project around the framework.

Cheers

Jason Araujo

unread,
Mar 8, 2018, 1:09:46 PM3/8/18
to StrangeIoC
Well, never mind. I'm not sure what the issue was, but I managed to work around it by restructuring the way I was doing things.
But if anyone in the future reads this and has any idea what might have gone wrong, I'd still be really interested to know.

--
You received this message because you are subscribed to a topic in the Google Groups "StrangeIoC" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/strangeioc/HvQqfRNF5kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to strangeioc+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jason Araujo
Unity3D, VR, Installation Art, Creative Code

wcorwin

unread,
Mar 8, 2018, 3:09:07 PM3/8/18
to StrangeIoC
Without better knowledge of the signals, commands and context bindings, it's hard to say. I can certainly confirm that all of my command sequences work as intended. Calling Command.Retain/Release in a threaded environment can be interesting, and simple loops of command -> signal -> command can make things just as confusing. But there's not a lot that can go wrong win the default use case. Sorry I'm not more help! Feel free to share more info if necessary. 

Jason Araujo

unread,
Mar 13, 2018, 11:40:14 AM3/13/18
to StrangeIoC
Wow ok, now I am truly confused. There is something strange (hah) afoot here.

This issue came up again in another context, and so I've had to debug it.

My steps were:
  • Create a TestView / Mediator / Context with NO links to any project code (except for my base context which extends MVCSContext to use signals)
  • Create a TestCommand which is a one-shot, and a TestRetainCommand which uses a coroutine to Retain, wait one second, then Release
  • Copy the StrangeIoC framework out of my current project and into a blank project
  • Copy the Test View/Moderator/Context and two test commands into the new project alongside strange
Now things get weird. In my existing project, this new clean uncluttered Test View/Context/Mediator exhibits the exact same behavior I described above:
If I fire the start signal with the one-shot test command, and the TestRetainCommand, both command fire twice. This stays consistent depending on how many commands I chain, for example:

commandBinder.Bind<TestCommandSignal>().InSequence()
               
.To<TestCommand>()
               
.To<TestCommand>()
               
.To<TestCommand>()
               
.To<TestCommand>()  
               
.To<TestRetainCommand>();

This will execute each command 5 times.

In my NEW, CLEAN project, the EXACT same code behaves as expected, each command running only once. What?! As I mentioned, this new Test context etc. is not connected at all to any other code in my project. The only common link is StrangeIoC, as well as my custom BaseContext.


So, I went one step further and included ALL of my Strange-related code into the new clean project. I have all of my strange contexts, commands, signals, etc all with one common root folder.
So I brought in the whole entire system, and merely removed editor scripts (because they depend on other extensions, etc.) and some extensions (such as string extensions to remove path illegal characters when saving to disk, etc. nothing major)

So... the new project with the entirety of my strange-related code base performs as expected, with no repetitions of commands.

I have no idea what is going on here, and the most sensible but terribly arduous path I can see right now is to slowly drag all of my assets and code from my old project into a new project until I discover what is causing this (or perhaps the issue will just magically disappear?).

Anyway, not sure anyone would have any new input based on that, but just wanted to give an update so that I can share the pain :p

wcorwin

unread,
Mar 13, 2018, 1:28:07 PM3/13/18
to StrangeIoC
I feel for you, that's just plain weird. Drop some breakpoints in and see where we're going wrong. Presumably you can see in a stack trace very easily where things are going wrong, or at least gain a better understanding of "X is happening five times, which causes Y to happen five times". Since it sounds like you're using source and not compiling an assembly, I would drop break points in to Signal Command Binder, possibly Command, and definitely TestCommand and TestRetainCommand.

After that, some unlikely suggestions, in no particular order:

Are you subclassing contexts? I have a "SharedContext" file that everything inherits from, and it would be possible to run certain setup commands multiple times if I tried.

Make sure you're running through your context critical setup paths only once.

Take a look at your scene hierarchy and ensure everything is as you expect it. Any nested contexts should be where they ought to be. A single context view on each context

Script execution order? I don't have any particular suggestion here, but things could certainly go sideways if one context were prioritized over another and the order screwed something up. This is very unlikely, but possible.

Check your cross context bindings. Same deal, another context may somehow be binding to your sequence or signal.

Reply all
Reply to author
Forward
0 new messages