Skip to content Skip to sidebar Skip to footer

Traceview Shows Some Methods Arent Being Called For 200ms Or More

Traceview shows that updatePhysics() is being called every 10ms or so and it takes about 8ms to run. The methods that I call inside updatePhysics are only running once every 5 or 6

Solution 1:

Most likely somewhere in your thread you're calling thread.Sleep(0) or thread.Yield() or something like that. This will cause a thread to yield to other threads that are being scheduled. And it will often take 10ms or more before the thread gets scheduled back in. I think traceview doesn't understand this fully and counts the time the thread is in suspended state as being active.

Most games use a constant game loop, a real while(true) that never yields to anything.

Some other comments:

I would try the code without the try-catch block, this will slow things down considerabely. Als remove the threadpriority line, this is an OS call and could be slow, and would not add any speed in case of a bug. (It should be fine on normal priority)

Also are you sure this is correct:

time2 = System.nanoTime()/100000; //Getcurrenttimefloat delta = (time2 - time1)/1000f;

I don't see why you require to devide the delta and the current time. Either convert the time from nanotime to seconds (or whatever you require), and then have a delta in seconds. Or keep time in nanoseconds and convert the delta to seconds. Now you first convert to seconds and then to 1/1000th of a second.

Post a Comment for "Traceview Shows Some Methods Arent Being Called For 200ms Or More"