Copy link to clipboard
Copied
Hi!
I have a popup parameter representing the effects stack.
I update it during PF_Cmd_UPDATE_PARAMS_UI.
I update it with a std::string set to "(none)", then for each effect, I append "|" + the effect's name.
It usually works fine but I sometimes get a crash.
I check all possible AE errors with if (err = PF_ABORT(in_data)) {} and return without problems.
But when it comes to appending the std::string, I crash.
So here's my question: how can I check if it throws an error when it's not a PF_Err function?
I tried this way, but still crashes:
try{
names.append(effect_nameAC);
}catch( std::bad_alloc& ba){
err = PF_Err_OUT_OF_MEMORY;//also tried with PF_Err_INVALID_INDEX
ERR2(suites.StreamSuite4()->AEGP_DisposeStream( stream));
ERR2(suites.StreamSuite4()->AEGP_DisposeStream( parStream));
ERR2(suites.EffectSuite3()->AEGP_DisposeEffect( fxH));
ERR2(suites.EffectSuite3()->AEGP_DisposeEffect( effect_refH));
return err;
}
Thanx,
François
1 Correct answer
Got it! 🙂
Toby, you put me on the right track with this one:
I would suppose AE reserves exactly the amount of bytes for the param string you give it on the first call in PF_Cmd_PARAMS_SETUP
In fact, AE reserves 4096 bytes.
you should never send a string with more than the initially allocated number of characters to AE
That's where the bug was. To be safe, we should never send a string with more OR LESS than the initially allocated number of char.
So, for the record:
string stringP = param_copy[PAREN
...
Copy link to clipboard
Copied
std::string::append should work fine if you hand it proper null-terminated data
- Can you use a debugger to break on the crash?
- Try using a "catch(...)" to get all exception cases and put a breakpoint in that case
- Are you sure "effect_nameAC" is always a proper null-terminated char array?
Can't tell much from the incomplete code snippet you posted, e.g. where "names" is actually used (the Adobe functions only use char arrays, not std:string, as far as I know) or where "effect_nameAC" comes from.
Copy link to clipboard
Copied
Hi Toby,
thanx for the answer.
I tried to use a try{}catch(...){} but no luck.
But I think I know where it crashes now. I think it is on this line:
strcpy((char*)param_copy[PARENT_INDEX].u.pd.u.namesptr, popupnames.c_str());
is there a way to check if the copy is safe to do before actually copying?
Cheers,
François

Copy link to clipboard
Copied
The popup menu entries are not intended to be modified after the popup parameter is created.
Adobe explicitly warns you not to do this in the SDK. Maybe that is where your errors come from?
Copy link to clipboard
Copied
Well, it does work most of the time, that's the (really annoying!) point. 😞
I do it like described in this thread: Update popup parameter list dynamically
After searching a bit more, I noticed it doesn't crash exactly on the copy, but right after the copy, I mean it crashes on the next PF_Err operation, no matter what is the operation...
I even tried to delay the copy, by copying at idle time, just to be sure AE's not working anymore when I copy, but same result...
I would say it's a memory issue, but I don't know how to solve it.
Cheers,
François

Copy link to clipboard
Copied
Have you filled a large enough amount of bytes in the initial setup? I would suppose AE reserves exactly the amount of bytes for the param string you give it on the first call in PF_Cmd_PARAMS_SETUP and on subsequent calls in PF_Cmd_UPDATE_PARAMS_UI you should never send a string with more than the initially allocated number of characters to AE.
Copy link to clipboard
Copied
Got it! 🙂
Toby, you put me on the right track with this one:
I would suppose AE reserves exactly the amount of bytes for the param string you give it on the first call in PF_Cmd_PARAMS_SETUP
In fact, AE reserves 4096 bytes.
you should never send a string with more than the initially allocated number of characters to AE
That's where the bug was. To be safe, we should never send a string with more OR LESS than the initially allocated number of char.
So, for the record:
string stringP = param_copy[PARENT_INDEX].u.pd.u.namesptr; // like this I know the real size of namesptr
names.resize(stringP.size(),'|'); // add '|' in the blank space, otherwise, it will be filled with zeros... '|' won't appear in the list
strcpy((char*)param_copy[PARENT_INDEX].u.pd.u.namesptr, names.c_str()); // finally copy
Thanx for the help!
François

