Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck in collecting data when I try to debug in android studio

I was try to write a code by singleton pattern.

this is my MainActivity.

public class MainActivity extends AppCompatActivity {

public static MainActivity activity;
public TouchSensor touchSensor;
public SurfaceViewThread surfaceViewThread;
public TriggerChecker triggerChecker;

public Physics physics;

//public static Handler mHandler = new Handler();

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    activity = this;
    surfaceViewThread = SurfaceViewThread.getInstance();
    touchSensor = TouchSensor.getInstance();
    triggerChecker = TriggerChecker.getInstance();
    physics = Physics.getInstance();

    touchSensor.start();
    triggerChecker.start();
    physics.start();
    //surfaceViewThread is already started.

    activity.setContentView(surfaceViewThread);
}

and this is a code what I try to write by singleton pattern.

public class SurfaceViewThread extends SurfaceView implements Runnable, SurfaceHolder.Callback {

private static SurfaceViewThread surfaceViewThread = new SurfaceViewThread();

private static Camera camera;
private SurfaceHolder holder;
private Thread thread;
private boolean run;

private Vector<ObjectGraphic> objects;
private Vector<Graphic> UIs;
private ObjectGraphic field;

private Vector<ObjectGraphic> draws;
private ComponentMessage componentMessage;

public static SurfaceViewThread getInstance()
{
    if(surfaceViewThread == null)
        surfaceViewThread = new SurfaceViewThread();
    return surfaceViewThread;
}
private SurfaceViewThread()
{
    super(activity.getApplicationContext());
    camera = new Camera();
    getHolder().addCallback(this);
    holder = getHolder();
    objects = new Vector<>();
    UIs = new Vector<>();

    draws = new Vector<>();

    run = false;

    componentMessage = new ComponentMessage();
}

and when I build this code, Camera class crashed by NullPointException.

public class Camera extends GameObject {

private Rect area;
private int sight;
private int maxSight = 50;
private int minSight = 10;
private int[] fieldOfView;//{vertical, horizontal}
private int[] maxFieldOfView = new int[] { 60, 45 };
private int[] minFieldOfView = new int[] { 10, 10 };

public Camera()
{
    super();
    area = new Rect();
    this.fieldOfView = new int[] { 60, 45 };
    objectMatrix.Rotate(objectMatrix.xVector(), Math.toRadians(-45));

    setDisplayVector();
}
private void setSight()
{
    double angle = Math.PI/2 - Math.acos(new Common_Math.Matrix1X4(0, 1, 0, 0).Inner(objectMatrix.zVector().Invert()));
    if(angle < 0 && angle > - Math.PI/2) {
        double t = -objectMatrix.qVector().getY() / objectMatrix.zVector().getY();
        int x = (int) (objectMatrix.zVector().getX() * t + objectMatrix.qVector().getX());
        int z = (int) (objectMatrix.zVector().getZ() * t + objectMatrix.qVector().getZ());

        sight = (int)Math.sqrt(Math.pow((x - objectMatrix.qVector().getX()), 2) + Math.pow((objectMatrix.qVector().getY()), 2) + Math.pow((z - objectMatrix.qVector().getZ()), 2));
        if(sight < minSight)
            sight = minSight;
    }
    else
    {
        sight = maxSight;
    }
}
private void setDisplayVector()
{
    setSight();
    Common_Math.Matrix1X4 upVector, downVector, leftVector, rightVector;
    Common_Math.Matrix1X4 zVector = objectMatrix.zVector();

    upVector = zVector.Rotate(objectMatrix.xVector(), fieldOfView[0]);
    downVector = zVector.Rotate(objectMatrix.xVector(), -fieldOfView[0]);
    leftVector = zVector.Rotate(objectMatrix.yVector(), fieldOfView[1]);
    rightVector = zVector.Rotate(objectMatrix.yVector(), -fieldOfView[1]);

    double angle = Math.PI/2 - Math.acos(new Common_Math.Matrix1X4(0, 1, 0, 0).Inner(objectMatrix.zVector().Invert()));
    upVector = upVector.Scaled((int)(Math.abs(objectMatrix.qVector().getY() * Math.tan(angle + fieldOfView[0]))));
    downVector = downVector.Scaled((int)(Math.abs(objectMatrix.qVector().getY() * Math.tan(angle - fieldOfView[0]))));
    leftVector = leftVector.Scaled((int)(sight * Math.asin(fieldOfView[1])));
    rightVector = rightVector.Scaled((int)(sight * Math.asin(fieldOfView[1])));

    area.left = (int) objectMatrix.qVector().Add(leftVector).getX();
    area.top = (int) objectMatrix.qVector().Add(upVector).getY();
    area.right = (int) objectMatrix.qVector().Add(rightVector).getX();
    area.bottom = (int) objectMatrix.qVector().Add(downVector).getY();
}

and this is GameObject class

public class GameObject {

protected GameObject upperGameObject;//if upperGameObject is null, this GameObject is parent GameObject.

protected Common_Math.Matrix4X4 objectMatrix;
private Vector<SeaWeedComponent> componentVector;

public GameObject()
{
    objectMatrix = new Common_Math.Matrix4X4();
    AllocatePhysicsSpace();
    componentVector = new Vector<>();
}

and Matrix4x4 class

public static class Matrix4X4
{
    private Matrix1X4 xVector, yVector, zVector, qVector;

    public Matrix4X4() {
        xVector = new Matrix1X4(1, 0, 0, 0);
        yVector = new Matrix1X4(0, 1, 0, 0);
        zVector = new Matrix1X4(0, 0, 1, 0);
        qVector = new Matrix1X4(0, 0, 0, 1);
    }

so I was check a break point to see why this happened but when I debug this, every variables are stuck at "Collecting data.." and nothing happen. and even debuger respond is slow down.

I can't guess why this happen. is there any problem in my code? how can I see the variables?

like image 321
신승빈 Avatar asked Sep 06 '25 03:09

신승빈


1 Answers

I came across this issue. To solve, for a single object, what helped me was to right-click the stuck object, then go to view as and select object instead of Kotlin class.

enter image description here

enter image description here

as a definitive measure, this answer could be a possible solution, but it does not work for me on

Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
Runtime version: 11.0.15+0-b2043.56-8887301 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.6.2
like image 134
Victor R. Oliveira Avatar answered Sep 08 '25 13:09

Victor R. Oliveira