01-29-2021, 09:13 AM
(01-20-2021, 01:03 PM)garrett Wrote: Pushing and popping context is required whenever your plugin is messaged through any other means than via Illustrator directly; which is to say, if your PluginMain() function (which hdi_core abstracts away so you don't have to deal with it) is NOT called, then you have to push context if you want to interact with Illustrator and pop context when you're done interacting with Illustrator. An example of this is when the OS itself messages your plugin, perhaps in response to e.g. some event in a custom widget you have created completely from scratch, or in response to a timer you registered directly with the OS, or response to your interacting with a third-party library that later calls your code of its own accord.
I think I have the situation you described. In a custom art update callback, I call a function in a library I created (separate file with its own namespace) to manipulate art. It accepts a reference to an art (in my case an aiArtHandle) and returns a group containing the original art with transformations, along with new art. It works fine when called from a menu or button, but as part of a custom art update callback, it fails. For now, calling uid()->name() on art the plugin creates works for a while, then after a few for loops, it crashes, suggesting that art has moved in memory.
So I modified the custom art update callback like this:
Code:
HDI_CORE_ILLUSTRATOR->pushContext();
AIArtHandle newArt = myLib::xform::xformArt(thisArt->aiArtHandle(), someValue);
HDI_CORE_ILLUSTRATOR->popContext();
I tried it with and without a return value, thinking it might pause the update thread until the library was finished, but that didn't make a difference. I'm SO close on finishing this. Any suggestions would be very much appreciated.