Results 1 to 3 of 3

Thread: Call to fract causing crash

  1. #1

    Call to fract causing crash

    This may well be a bug in the implementation I'm using, but I wanted to check if this is sound code.

    In my kernel I have the following lines:
    Code :
    float func (float4 p) {
        float4 ip, fp;
        fp = fract(p, &ip);
        [rest of function snipped....]
    This compiles fine, but at runtime (on the CPU under snow leopard) produces a <EXC_BAD_ACCESS> error. Am I doing something wrong here? Have I mis-interpretted how to use that function?

    Removing the call to fract cures the problem.

  2. #2

    Re: Not a call to fract causing crash

    Ok, forget that. It's not the call to fract, but something else. I think the optimiser must be playing tricks with me as I was putting printf's in before/after that call. As I could only see the ones before I assumed it was that line. Seems like some instruction re-ordering is going on.

    I'm now in the process of, having stripped everything out of this function, slowly reintroducing code a line at a time.

  3. #3

    Re: Call to fract causing crash

    Ok, just to close this, I found my problem.

    Once I'd gotten the integer part of my vector with fract I cast it to an int4

    Code :
    float4 fp,ip;
    fp = fract(p, &ip);
    int4 idx = (int4) ip;

    I then used the components of idx to index into an array. The problem is that that cast is illegal according to the spec, but Snow Leopard allows it (at least when targeting the CPU) and what it does is copy the float vector into the int vector with no float->int conversion. The result is that index becomes huge, and I overflowed my arrays in a big way.

    When I removed the call to fract, I replaced it with zero. Floating point zero == integer zero, so there was no problem.

    Hopefully this might stop somebody else doing the same. Nasty one to track down. Thank god for printf.

Similar Threads

  1. Using IBO offset causing crash with OpenGLES 1.1
    By Ro_land in forum OpenGL ES 1.X - fixed function hardware
    Replies: 1
    Last Post: 01-19-2012, 01:30 AM
  2. Why does EGL call glGetIntegerv when I call wglSwapBuffer?
    By teriba in forum Cross API and window system integration
    Replies: 0
    Last Post: 07-23-2009, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •