#rotate vector function causes server to crash?

1 messages · Page 1 of 1 (latest)

pliant plume
#

Every 20 ticks in a sync repeating task I loop over players in a certain gamestate. While looping over each player I call this helper function to rotate a vector around another, but it crashes the server? I have no idea why.

#
    private Vector rotate(Vector toRotate, Vector around, double angle) {
        if (angle == 0.0) {
            // line 133 V
            return toRotate;
        }

        double vx = around.getX(), vy = around.getY(), vz = around.getZ();
        double x = toRotate.getX(), y = toRotate.getY(), z = toRotate.getZ();
        double sinA = Math.sin(Math.toRadians(angle)), cosA = Math.cos(Math.toRadians(angle));

        double x1 = x * ((vx * vx) * (1 - cosA) + cosA) + y * ((vx * vy) * (1 - cosA) - vz * sinA) + z * ((vx * vz) * (1 - cosA) + vy * sinA);
        double y1 = x * ((vy * vx) * (1 - cosA) + vz * sinA) + y * ((vy * vy) * (1 - cosA) + cosA) + z * ((vy * vz) * (1 - cosA) - vx * sinA);
        double z1 = x * ((vz * vx) * (1 - cosA) - vy * sinA) + y * ((vz * vy) * (1 - cosA) + vx * sinA) + z * ((vz * vz) * (1 - cosA) + cosA);

        return new Vector(x1, y1, z1);
    }
vestal yoke
#

what's line 113 and 51?

pliant plume
#

its the return statement

#

line 51 is where it calls the function which calls the rotate function

vestal yoke
#

?paste the whole class so we can see the proper line numbers etc

pliant plume
vestal yoke
#

your for loop near line 113 never ends, or it's way too large

pliant plume
#

at 111?

vestal yoke
#

yeah

#

how many blocks are you looping over?

pliant plume
#

when I remove line 100 it runs fine though it runs fine

pliant plume
vestal yoke
#

print out "min" and "max"

#

your rotate method probably does some weird stuff

#

and you are now looping over millions of blocks

pliant plume
#

the schematic im testing with's dimensions are (15.0, 26.0, 17.0)

vestal yoke
#

print out the value of "min" and "max" before you go into the nested loop

pliant plume
vestal yoke
#

print out the x y and z values in your inner loop, then check whether it only accesses the blocks you expect it to

pliant plume
#

do you think that these sort of operations just requires more ram to run?

vestal yoke
#

usually not, that's not many blocks

pliant plume
#

im pretty sure the nested for loops loop over all the blocks, and just checks if it's on the edge

vestal yoke
#

unless you go for like 100k blocks, it should be fine (well it would cause lag, but shouldnt crash everything)

pliant plume
#

true

#

here ill show a particle at every spot it loops regardless of if it is on the edge or not

#

yeah it looks like the for is only looping over the region it should be

vestal yoke
#

weird, sorry then I have no clue

pliant plume
#

maybe it isn't looping over the right area after the rotation

#

oh yeah

#

theres the issue

#

somehow after rotating it it becomes a recursive loop

#

never ends

vestal yoke
#

yeah that's what I suspected

#

but what exactly causes it, idk

#

you'll have to debug it 😛 add tons of debug output

pliant plume
#

yeah so i dont think max is supposed to be (-2.4887484799999994E8, 6.2958062999999985E7, 2.1641046399999997E8)