Skip to main content
Inspiring
October 30, 2017
Answered

Sending data via IdleRefcon

  • October 30, 2017
  • 1 reply
  • 584 views

Hi. Inside the entryPointFunc I create my data and send it like this:

my_global_data myStruct;

AEFX_CLR_STRUCT(myStruct);

myStruct.my_int = 5;

my_global_dataP globP = &myStruct;

AEGP_IdleRefcon idleRefcon = reinterpret_cast<AEGP_IdleRefcon>(globP);

ERR(suites.RegisterSuite5()->AEGP_RegisterIdleHook(S_my_id, IdleHook, idleRefcon));

When I retrieve the data inside the idleHook the address looks correct but the data is different:

my_global_dataP globP = reinterpret_cast<my_global_dataP>(refconP);

Any ideas what could be the cause/s of my problem? Thank you.

This topic has been closed for replies.
Correct answer shachar carmi

you are correct. you were saving the address of a locally defined variable

which invalidates as it's scope (the global setup function) ends.

when refering to that address later, you're accessing some bit of ram that

has since been re-used.

using "new" allocates memory from that heep instead of the stack, which

will remain valid until "delete" is called.

you should call "delete" for this mem bit during global setdown.

for more reliable memory management, you should probably use AE's memory

suite for allocation instead of "new" and "delete".

On Mon, Oct 30, 2017 at 10:25 AM, JamesWhiffin555 <forums_noreply@adobe.com>

1 reply

Inspiring
October 30, 2017

I think I have to do my_global_dataP globP =  new my_global_data, or use the handles suite I guess?

shachar carmiCommunity ExpertCorrect answer
Community Expert
October 30, 2017

you are correct. you were saving the address of a locally defined variable

which invalidates as it's scope (the global setup function) ends.

when refering to that address later, you're accessing some bit of ram that

has since been re-used.

using "new" allocates memory from that heep instead of the stack, which

will remain valid until "delete" is called.

you should call "delete" for this mem bit during global setdown.

for more reliable memory management, you should probably use AE's memory

suite for allocation instead of "new" and "delete".

On Mon, Oct 30, 2017 at 10:25 AM, JamesWhiffin555 <forums_noreply@adobe.com>