Menu

#8 Fix for Obstruction editor crash

open
nobody
None
5
2004-01-04
2004-01-04
No

I found a small divide by zero when working with the
obstruction editor and a small bug where it refused to
block the lower right corner. I was able to compile the
1.0 source files and debug it. This problem also
happened with the 1.1 binaries. The problem is in
primitives.hpp in the common folder.

line 171
slope = float(y2 - y1) / (x2 - x1);

changed to

if(x1 != x2) {
slope = float(y2 - y1) / (x2 - x1);
}

it seems you where double checking the slope but forget
to recheck for a divide by 0 error. This may not be
what you want but it will stop the crashes.

as for the lower right corner to simple fixes.

line 117 and 118
y1 = bracket<int>(y1, clipper.top, clipper.bottom - 1);
y2 = bracket<int>(y2, clipper.top, clipper.bottom - 1);

change to
y1 = bracket<int>(y1, clipper.top, clipper.bottom);
y2 = bracket<int>(y2, clipper.top, clipper.bottom);

line 136 and 137
x1 = bracket<int>(x1, clipper.left, clipper.right - 1);
x2 = bracket<int>(x2, clipper.left, clipper.right - 1);

change to
x1 = bracket<int>(x1, clipper.left, clipper.right);
x2 = bracket<int>(x2, clipper.left, clipper.right);

I don't have any diff utils on my laptop or I would make
you a patch file but here is the edited primitives.hpp
with comments you cant miss.... just look for the

//<---------------------Made a Change Here

Discussion

  • William Oldenburg

    Updated 1.0 Primitives file

     
  • Brian Robb

    Brian Robb - 2004-02-10

    Logged In: YES
    user_id=387078

    I'm not sure this is right, if you look at the code:

    // vertical (simplified clipping)
    if (x1 == x2) {
    ...
    }

    // horizontal (simplified clipping)
    else if (y1 == y2) {
    ...
    }

    // other lines (diagonal)
    else {
    float slope = float(y2 - y1) / (x2 - x1);
    ...
    }

    At the point that the float slope = float(y2 - y1) / (x2 -
    x1) is performed, x1 == x2 has already been checked, so what? :)

     
  • William Oldenburg

    Logged In: YES
    user_id=545559

    You are correct that you did make a check to see earlier but
    then you ran the clip_segment function which can change
    the values and cause a divide by zero error. trust me it
    happened to me every time I tried to use the editor. When I
    ran it through a debugger you were attempting to calculate
    the slope when x1 and x2 where the same. This was giving a
    divide by zero error and causeing the whole thing to crash.

     
  • Alex Rosario

    Alex Rosario - 2005-02-08

    Logged In: YES
    user_id=988268

    slope should be (y2 + 1 - y1)/(x2 + 1 - x1)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.