Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Photoshop CC 2014 Extension - CEP Event callback is triggered multiple times per single event

$
0
0

Trying to make my extensions listen for bunch of events and it's turning out to be a real pain in the ***.

I'm hoping there's someone here who has a bit more experience playing around with these.

 

I used the example code from here ( Page 43 ): http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/creativesuite/pdfs/CC14_Extension_S DK.pdf

 

I've modified the code just a little. I removed some unnecessary things from it. I also added a counter, to try to visualize the issue.

 

Every time I pasted the code here, the global variable seemed to duplicate. So, eeeeh...  the example code can be found here.

 

The problem is:

I close one document to trigger the event, but for some reason the callback seems to run multiple times.

Even better, it doesn't seem to be super consistent about it. Sometimes it repeats only couple of times and sometimes it repeats 160 times.

It seems like every time the extension panel is reopened, it comes up with a new number.

 

Currently, if I close a document, it seems to trigger the callback 15 times

 

Since this is screenshot, you'll have to take my word for it. I only closed a single document and the code ran 15 times.

Screen Shot 2015-04-18 at 21.21.28.png

 

Am I doing something wrong by any chance?

 

edit:

I believe I just found out the reason and a way to recreate the issue.

I've occasionally tested the extension by closing and opening the panel, which seems to have caused the issue.

It looks like every time I close and then open the panel, it... adds one more run time to the stack.

- Refreshing the panel from chrome doesn't seem to affect it.

 

When I restart photoshop, it resets. So after the very first opening of the panel, the event triggers the callback only once.

 

-------

 

I forgot to mention that the host application events work just fine without these issues.

In fact, I tried to use documentAfterActivate before, but as far as I could find, there is no way to kind of filter out specific events within host application events.
For instance, I can't specify something different to happen when a new document is opened.

 

 

As very much a side note:

documentAfterActivate has its own side effect due to the way photoshop works.

 

It is triggered when you:

  • Create a new document
  • Open a new document
  • Switch to an open document

It's the "Switch to an open document" part that makes this event listener also trigger when you close a document.

Because when you close a document, photoshop switches back to the previous document and that in turn triggers the event listener when it shouldn't, I suppose.

Of course it doesn't trigger the event when you close the last document as there is no document to switch to at that point.

 

...but this is beyond the scope of the original question.


Viewing all articles
Browse latest Browse all 12244


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>