rpgtoolkit / trans3

The Official GitHub repository for the RPG Toolkit Engine version 3.
http://www.rpgtoolkit.net
12 stars 2 forks source link

Vector Crash #44

Open nyttimangus opened 10 years ago

nyttimangus commented 10 years ago

I got this error:

vectorcrash

I believe it was caused by this line of code:

        nullVector(vectorExists(4, 3, 3));

which references these two functions:

function nullVector(vector)
{
boardGetVector(castNum(vector), type, pointCount, layer, isClosed, attributes);
boardSetVector(castNum(vector), tkVT_WAYPOINT, pointCount, layer, isClosed, attributes);
}

and

function vectorExists(x, y, l)
{
leftx = ((32 * x) - 32);
rightx = (32 * x);
topy = ((32 * y) - 32);
bottomy = (32 * y);
vectorCount = boardGetVector();
for(index = 0; index < vectorCount; index++)
{
    boardGetVector(index, type, pointCount, layer, isClosed, attributes);
    if(pointCount == 4 && layer == l)
    {
        boardGetVectorPoint(index, 0, x[0], y[0])
        boardGetVectorPoint(index, 1, x[1], y[1])
        boardGetVectorPoint(index, 2, x[2], y[2])
        boardGetVectorPoint(index, 3, x[3], y[3])
        if(x[0] == x[1])
        {
            if(x[0] == leftx || x[0] == rightx)
            {
                if(x[2] == leftx || x[2] == rightx)
                {
                    branch(:branch);
                }
            }
        }
        elseif(x[0] == x[2])
        {
            if(x[0] == leftx || x[0] == rightx)
            {
                if(x[3] == leftx || x[3] == rightx)
                {
                    branch(:branch);
                }
            }
        }
        elseif(x[0] == x[3])
        {
            if(x[0] == leftx || x[0] == rightx)
            {
                if(x[1] == leftx || x[1] == rightx)
                {
                    branch(:branch);
                }
            }
        }
        if(proceed == 1)
        {
:branch
            if(y[0] == y[1])
            {
                if(y[0] == topy || y[0] == bottomy)
                {
                    if(y[2] == topy || y[2] == bottomy)
                    {
                        return index;
                    }
                }
            }
            elseif(y[0] == y[2])
            {
                if(y[0] == topy || y[0] == bottomy)
                {
                    if(y[3] == topy || y[3] == bottomy)
                    {
                        return index;
                    }
                }
            }
            elseif(y[0] == y[3])
            {
                if(y[0] == topy || y[0] == bottomy)
                {
                    if(y[1] == topy || y[1] == bottomy)
                    {
                        return index;
                    }
                }
            }
        }
    }
}
//  debugger("Vector not found");
return -1;
}
nyttimangus commented 10 years ago

Yeah, these functions are integral to "An Altered Course." I had another of the same type of crash in another place.

swordmaster2k commented 10 years ago

I'll look into it.

swordmaster2k commented 10 years ago

Provide me with a link to your latest project files for "An Altered Course", thanks.

nyttimangus commented 10 years ago

The files are open to the public here (alternate download format): http://www.solovid.net/an-altered-course.html

swordmaster2k commented 10 years ago

At what point in "An Altered Course" does this issue occur?

nyttimangus commented 10 years ago

I believe this is run from "raca.prg" from an on pickup program to the sprite "raca.itm" on the first board ("garden.brd") in the southwest corner. I am assuming the same issue would be encountered anywhere those two functions are used together. If you are curious how the two functions work, here is a brief explanation:

nullVector() simply takes a vector handle as a parameter and changes its type from solid to waypoint. I would check this function first because it would be easier to test.

vectorExists() returns the handle of a one-tile-square vector at the tile-coordinate passed as a parameter. This coding is more complex, but it mainly just uses boardGetVectorPoint().

So really, you only probably need to check that these three engine functions work: boardGetVector(), boardSetVector(), and boardGetVectorPoint(). If all of those worked perfectly, I would assume this issue would not exist.