|
|
Thread Tools | Display Modes |
04-28-2014, 02:00 PM | #1 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Reaper on Mac OS crashes when using certain command IDs with Main_OnCommand
Hi,
Does anyone have an idea as to why I would be getting "Bad_access" violation errors when passing certain command IDs to Main_OnCommand? In particular... Trying to use Main_OnCommand with 41042, 41043, 41044 and 41045 (go measure/beat forward/backward). Strangely enough with all of the four commands I am getting "bad access" violation errors on Mac OS. All the other command IDs I tried seem to produce no such errors. I made sure Main_OnCommand and, just in case, Main_OnCommandEx are initialized with the IMPAPI macro. Are there any other API functions that need to be initialized for making Main_OnCommand* calls to work? O, BTW, I am calling Main_OnCommand with these IDs from the CommandSelector hook function. Some more information: - I am compiling a C/C++ extension using Xcode 5.1. - The OS is Mavericks (10.9.2). - Reaper version is the latest (4.61.x). Thanks for any help/suggestions. Best, Victor |
05-01-2014, 12:29 PM | #2 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 16,117
|
Can you provide a crash report? Call stack? etc...
|
05-01-2014, 10:39 PM | #3 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Diagnostics log is attached
Thanks Justin.
I looked at the diagnostics log and it seems that, among other things, it contains a lot of calls to the Main_OnCommand and Main_OnCommandEx functions. I am attaching the whole log here as you will probably be able to identify the cause much quicker. Thanks a lot. Victor |
05-05-2014, 10:07 PM | #4 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Any ideas?
Anyone can help? Do you need any more information?
Thanks, V |
05-06-2014, 12:25 AM | #5 |
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
Hi vtsaran, we'd need the code to make sure of it but I think you are just facing some code re-entrance issues...
You should protect your command hook against it (here's an example: https://code.google.com/p/sws-extens...tension.cpp#80) |
05-06-2014, 07:04 AM | #6 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 16,117
|
It appears your hook function is calling Main_OnCommand(), which is calling your hook function, which is calling Main_OnCommand(), which ... stack overflow.
|
05-11-2014, 12:16 AM | #7 | |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Quote:
1. Register the hook with if (!rec->Register("hookcommand", (void*)commandSelector)) { // registering the hook function failed ... } 2. In my commandSelector function, I am attempting to augment the actions for some default Reaper commands, like this: static bool commandSelector(int commandId, int flag) { if (commandId == cidGoMeasureForward) { Main_OnCommand(41042, 0); // do some additional tasks here return true; } else if (commandId == cidGoMeasureBackward) { Main_OnCommand(41043, 0); // do some additional tasks here return true; } else if (commandId == cidGoBeatForward) { Main_OnCommand(41044, 0); // do additional tasks return true; } else if (commandId == cidGoBeatBackward) { Main_OnCommand(41045, 0); // do some additional tasks here return true; } // not our command return false; } the cid are defined using the #define directive, e.g. #define cidGoMeasureForward 41042 The 41042 and 41043 crash Reaper when tied to shortcut keys, e.g. "page up" and "page down". The 41044 and 41045 work just fine no matter what shortcut keys I assigned them to. Thanks for your help. Victor |
|
05-12-2014, 11:15 AM | #8 | |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 16,117
|
Quote:
Code:
int g_hook_depth; static bool commandSelector(int commandId, int flag) { if (!g_hook_depth && commandId == 41042) { g_hook_depth ++; Main_OnCommand(41042, 0); // do some additional tasks here g_hook_depth --; return true; } // not our command return false; } |
|
05-17-2014, 05:35 PM | #9 | |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Quote:
I guess, for the time being I will probably have to imitate the approach found in SWS extension where they seem to keep the stack of all commands relying on the WDL list utility. I was just hoping I could keep it simple as I really only need several commands for what I'm trying to do. |
|
05-19-2014, 01:16 AM | #10 |
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
I don't think a static WDL_PtrList like the one we use in SWS will help you here... It allows *some* recursion paths and prevent other ones a bit like Justin's solution above (except it only deals with sws actions, not native ones, e.g. a sws action "a" can call sws action "b" but, of course, "b" can neither call itself, nor "a").
There might be ways around it though... Can I ask what do you want to achieve exactly? i.e. what are those "additional tasks" you want to perform? |
05-19-2014, 11:00 AM | #11 | |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Quote:
Hope this makes sense. Victor |
|
05-19-2014, 11:18 AM | #12 |
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
^^ That sounds pretty cool, Victor. Thumbs up for improving accessibility!
Can I also put in a vote for something post-action in the form of feedback via the OSC Control Surface for 'action descriptions' like "ACTION"? That way we could build such things (and much more) without having to build extensions. Which would be a double win for accessibility, I guess.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ |
05-19-2014, 11:52 AM | #13 | |
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
Quote:
|
|
05-19-2014, 12:08 PM | #14 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Thanks for any help with this.
|
05-24-2014, 01:10 PM | #15 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
I will work around for the time being
I decided to work around the limitation for now and rely on API methods to do what I want to do. A bit more work, but I get a chance to learn more of SDK.
|
06-05-2014, 06:32 AM | #16 |
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
vtsaran, the post action hook thing is available in v4.70pre (http://forum.cockos.com/showthread.php?t=22836).
For more details, look for "hookpostcommand" in the generated reaper_plugin_functions.h |
07-14-2014, 11:34 AM | #17 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
A strange thing happens. When I generate the latest reaper_plugin_function.h from Reaper 4.7 and plug it into my existing project, I get a lot of errors. For one, there is a reference to the WDL_FastString class. However, even after resolving this problem, I am getting a bunch of errors from RPR_MIDI and other classes in reaper_plugin_function.h.
What version of WDL should I be using now? When I tried the latest (Git) source from the Cockos site, the errors didn't go away. Thanks for any help. |
07-14-2014, 01:52 PM | #18 |
Human being with feelings
Join Date: Nov 2010
Posts: 2,436
|
Delete SWS and try generating it again.
|
07-14-2014, 07:44 PM | #19 |
Human being with feelings
Join Date: Dec 2009
Location: Wellington, NZ
Posts: 300
|
WDL_FastString and whatever other pointers used by SWS are opaque so a simple:
Code:
class WDL_FastString; class RprMidiNote; class Whatever; #include "reaper_plugin_functions.h" |
07-14-2014, 08:50 PM | #20 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
I am not really using SWS, writing my own extension.
I wish I was able to compile SWS, but that's a different topic altogether. |
07-15-2014, 06:24 AM | #21 |
Human being with feelings
Join Date: Nov 2010
Posts: 2,436
|
But the question is not if you use it, only if you have it installed. Because if you do, header will also include functions SWS exports...rest is in the Fingers' post
|
07-27-2014, 01:48 PM | #22 | |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Quote:
I just got a chance to look at the newly-implemented HookPostCommand functionally. Can you help me understand what I would put inside the callback it needs? Do I pass in the same command IDs I wanted to use with main_oncommand and, if yes, what would I do with them inside this callback? Thanks, Vic |
|
07-29-2014, 03:34 AM | #23 |
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
^ sorry vtsaran I do not understand the question, but here's how it works, let me know if it isn't clear enough...
1) You need a recent REAPER version, say v4.71 2) In your plugin extension entry point, you can add: Code:
rec->Register("hookpostcommand", (void*)hookPostCommandProc); Code:
void hookPostCommandProc(int iCmd, int flag) { WDL_FastString str; str.SetFormatted(512, "hookPostCommandProc: %s, flag=%d\r\n", kbd_getTextFromCmd(iCmd, NULL), flag); ShowConsoleMsg(str.Get()); } ___ About the SWS discussion above... SWS will soon compile "out of the box": in REAPER v4.72pre2+, the API functions header file will not contain functions exported by 3rd party extensions (like SWS) anymore -- unless you tick a new option when generating the said .h |
07-29-2014, 03:54 PM | #24 |
Human being with feelings
Join Date: Jan 2011
Posts: 64
|
Hello Jeffos,
Thanks for your help, however... I am not sure how this solves my initial problem, which is that using Main_OnCommand when used from inside the "hookcommand" and "hookcommand2" callbacks crash Reaper. This, as I understand, is a result of the recursion. When I attempted to call Main_OnCommand from the "hookpostcommand" callback, I got the same result, Reaper crash. |
Thread Tools | |
Display Modes | |
|
|