PDA

View Full Version : Shake Macro causing odd crash


osxrules
09-03-2007, 01:54 AM
I've come across some very strange behaviour in Shake after programming a few macros. If I call functions and return values in certain ways, it cause Shake to crash with a segmentation fault.

One example is if I do

float correct_quadrant(float a, float x1, float y1, float x2, float y2){
if(x2<x1 && y2>y1) return a;
}

image curve_path(...){
...
grad1 = correct_quadrant(grad1,x1,y1,x2,y2);
...
}

This crashes Shake immediately on adding the node and there are references to getVal() and asFloat() in the crash. If however, I add the code from the external function directly into the main one, it's fine and doesn't crash.

I thought that it maybe wasn't picking up the float type from the function argument and indeed when I change the function to:

float correct_quadrant(float a, float x1, float y1, float x2, float y2){
float value = a;
if(x2<x1 && y2>y1) value=a;
return value;
}

it doesn't crash. However, I tried other functions similar to the second one and as I'm using the node, it will crash completely at random times with the same crash error about getVal() asFloat(). When I remove the external function, it seems to be stable but I need to use external functions.

I guess I should just submit another bug report to Apple but I was wondering if any Macro developers had come across this before. I find that some 3rd party Macros will crash Shake at random too and I suspect it's a similar issue.

osxrules
09-03-2007, 12:19 PM
Ah, stupid mistake for the reproducible crash. I didn't have a return value in the external function for all cases, which is why it couldn't get the float value as there wasn't one being returned.

That still doesn't solve the random crashes though, which generates the same error even using the second form I mentioned above and despite the randomness, it definitely seems related to calling an external function because like I say, when no external functions are used, it seems to be stable.

pgraham
09-05-2007, 08:32 PM
Is grad1 an image? You're passing it into a float parameter of the function. Usually things named grad[number] are of type image, but you didn't include its declaration here. That could cause your crash.

Also, correct_quadrant version 2 always returns a. You might want to put an else condition so you know when it's not the correct quadrant.

osxrules
09-06-2007, 08:34 PM
Is grad1 an image? You're passing it into a float parameter of the function. Usually things named grad[number] are of type image, but you didn't include its declaration here. That could cause your crash.

Nope it's a float, I didn't include the declaration here but it comes just before it.

Also, correct_quadrant version 2 always returns a. You might want to put an else condition so you know when it's not the correct quadrant.

Yeah I tried that too and I tested when it was crashing by using printf statements (I hate how they only seem to flush on quitting Shake) and the random crashing occurred in the first condition. It should still work without an else though because the return value has been assigned.

I tried all sorts of things and sometimes I can use the macro for quite a while with an external function and other times it crashes just opening a project - normally it happens if I scrub the timeline quickly or quickly adjust keyframes. Just as a test, I removed all external functions and I've been using it like that since I posted the thread and I haven't had a single crash with all the code inside the main function.

That's the thing, it's not just this function, I tried it with a couple of different ones and it's doing the same thing.

If you want to check it out, here it is:

http://www.geocities.com/ajr650/curvepath.zip

It's basically a way to animate curved paths for things like writing, spray paint etc (add a blur node for spray paint). I see a few tutorials for animated writing and they expect you to use quickpaint and do one stroke for the whole thing.

How it works is you add the node, turn on auto-keyframing. Then click the point, move the timeline and then move the point again and it will draw the line. Once you have built up the curve, you can animate the in and out values at any point in the animation. It's a WIP but its functional.

The code changed since before but if you check out the code where it calls average_angle, you can replace this:

float gradA = 180;//average_angle(grad1,grad2);
float A = (grad1+grad2)/2;
float S = grad1-grad2;
gradA = fabs(S)<180?A:(A>=0)?A-180:A+180;

with this:

float gradA = average_angle(grad1,grad2);

and compare how stable they are doing various keyframing and things. One of the easiest ways to get it to crash was to have autokeyframing on, set a keyframe later on in the timeline and then quickly create one earlier. Like I say, without the external code, it doesn't crash for me but it's frequent (albeit completely random) using the external function.

Btw, thanks for writing the halftone macro, it's very useful. :thumbsup:

CGTalk Moderation
09-06-2007, 08:34 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.