Error handling with object_method_typed?


    Feb 18 2020 | 9:00 pm
    Hi folks, in the C SDK, I'm hitting a bit of a funny issue. I've got object_method_typed working properly, and am sending messages to various objects after finding them via their scripting names. But I'm hitting some situations where the message crashes Max when it's a bad message. I'm hoping it's possible to have Max just spit out an error message in this situation instead of crashing. The scenario where I can make a crash happen every time is sending a message of "list 1.2 3.4" to a flonum object. This is invalid, but when I do this in a max patcher, either with a message box that says "list 1.1 2.2" or "1.1 2.2", the flonum happily takes the first number and there's no crash. Sending it via object_method_typed as message symbol "list", and array of atoms of 2 floats crashes. Using the same code to send this message to a zl.rev object is fine, so it seems like it works ok *when this is a valid message*. Is there some way of either capturing the error sans crash or checking first to see if this is a valid message for the target object?
    thanks!

    • Feb 18 2020 | 9:30 pm
      Interestingly, if I try to send the same bad message (list 1.1 2.2) to a flonum using object_method_parse, I get an error message in the console and no crash. This doesn't seem intuitively like the right way to do it, but I suppose I could resort to making strings out of my args if this is the safest way to construct dynamic messages and know they won't crash. Opinions welcome!
    • Feb 25 2020 | 4:40 pm
      It can be confusing. For messages which are internally defined as A_GIMME the correct call to use is object_method_typed(). But for other messages, say one with A_FLOAT as the argument, you will likely want to use object_method().
      Hope this helps, Tim
    • Feb 26 2020 | 3:19 pm
      Thanks Tim, that's helpful. In my case, I don't know what the target item will receive because I'm actually coding a scripting extension to allow users to send messages in scheme/lisp, so what I'm writing is the foreign function interface. So far it seems ok to use object_method_typed in general; I managed to get that previous crash stopping, so I don't know what was going on there. Do you know if it's generally ok to use object_method_typed with a constructed list of atoms regardless of the signature? Or alternately, is there a way from C to find out what function I should use, given a target object determined at run time? Thanks for your help.
    • Mar 17 2020 | 6:43 pm
      In the Min-Devkit there is an example object called min.remote whose source code is @ https://github.com/Cycling74/min-devkit/blob/master/source/projects/min.remote/min.remote.cpp
      On line 35 a method is called on the "box". What happens inside of this to get to the correct incantation of object_method() and friends is on line 101 of the file @ https://github.com/Cycling74/min-api/blob/55c65a02a7d4133ac261908f5d47e1be2b7ef1fb/include/c74_min_patcher.h#L101 I hope this is helpful! Tim
    • Mar 18 2020 | 6:56 pm
      Thanks Tim! I will check that out, much appreciated! iain