简体   繁体   English

由于某种原因,检查冲突(是否存在相同坐标的对象)在几秒钟内使java崩溃

[英]For some reason checking collisions (are there objects in the same coordinates) crashes java in a few seconds

SOLVED I am working on my own java game engine that has it's own "physics engine", for some reason my new way of checking collisions crashes java? 解决了我正在开发自己的具有自己的“物理引擎”的Java游戏引擎,出于某种原因,我检查碰撞的新方法使Java崩溃了吗?

I am fairly new on java, and I have no idea what is going on, I don't see any problem in the code, nor do I think I would see it. 我在Java上还很陌生,我不知道发生了什么,我在代码中没有看到任何问题,我也不认为会看到它。

the complete source is available on github 完整的源代码可以在github上找到

the function in gameobject.java: gameobject.java中的函数:

private void checkAdvancedCollisions(objectManager o, gameObject i){
        if(!i.masterParent.engine_collisions){
            return;
        }
        LinkedList<String> ignore = tag;
        for(gameObject ga : children){
            ignore.addAll(ga.tag);
        }
        for(int xc : new Range(size)){
            for(int yc : new Range(size)){
                if(o.colliding(Math.round(i.x + xc), Math.round(i.y + yc), ignore)){
                    point1(i, o.collidingGA(xc, yc, ignore));
                }
                else if(o.colliding(Math.round(i.x + xc), Math.round(i.y + yc + 1), ignore)){
                    point2 = true;
                    point2(i, o.collidingGA(Math.round(i.x + xc), Math.round(i.y + yc + 1), ignore));
                }
                else{
                    colliding = false;
                    point2 = false;
                }
            }
        }
    }

the actual checking in objectmanager.java (should work fine): 在objectmanager.java中进行实际检查(应该工作正常):

public boolean colliding(int x, int y, LinkedList<String> ignore){
        for(gameObject i : object){
            if(i.getTag().contains("cursor") || i.getTag().containsAll(ignore)){}
            else{
                if((round(i.x) == x && round(i.y) == y)){
                    return true;
                }
            }
        }
        return false;
    }
    public gameObject collidingGA(int x, int y, LinkedList<String> ignore){
        for(gameObject i : object){
            if(i.getTag().contains("cursor") || i.getTag().containsAll(ignore)){}
            else{
                if((round(i.x) == x && round(i.y) == y)){
                    return i;
                }
            }
        }
        return null;
    }

and the java completely just stops when using this function, no error messages or anything 使用此功能时,java完全停止,没有错误消息或其他任何东西

Thanks for Joop Eggen for pointing out that the ignore list may contain endless. 感谢Joop Eggen指出忽略列表可能包含无尽的内容。 The code was to add all tags of the children to the list, while all gameobjects are children of themselves, causing an endless list. 代码是将所有子代的标签添加到列表中,而所有游戏对象都是其自身的子代,从而导致无休止的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM