Stop double-presenting every frame (task #47)
The engine synthesized an eglSwapBuffers on each detected frame boundary.
That duplicated the present Android's GLSurfaceView already performs after
every onDrawFrame return, so every frame reached the screen twice - the
second time from a buffer still holding the PREVIOUS frame.
The whole mechanism rested on a premise recorded 2026-09-18 and never
verified live: that nativeOnResume runs the guest's persistent loop on the
GLThread and never returns, leaving the framework unable to present. An
entry/exit counter added to GameRenderer.onDrawFrame shows that is false -
it returns every frame (entries=698 exits=697, the gap being the call in
flight). Rates match 1:1:
synthetic swaps 12.98/s (SWAPMARK, one line per swap)
onDrawFrame 12.69/s (so the framework swapped 12.69/s too)
The user saw this as the car jumping forward then back along its path.
Frame-by-frame the race clock stepped 1:10.06 -> 1:10.03 -> 1:10.09 ->
1:10.06, with presents arriving in pairs 10-20ms apart at a 218ms period -
exactly the synthetic swap period.
Letting the framework present is also what the real game does: libapp.so
cannot present at all (only EGL import is eglGetProcAddress; the string
"eglSwapBuffers" is absent from the binary), and on the A9 all 2,736
eglSwapBuffers calls in 46s came from Android's own framework.
Measured after, on the Pixel 6a:
frame interval median 89ms -> 17ms
p90 217ms -> 19ms
max 316ms -> 24ms
synthetic swaps 0 (verified, not merely absent from view)
onDrawFrame 12.69 -> 12.39/s (throughput deliberately unchanged)
User verdict: "Сейчас очень плавно". Throughput is untouched - this fixes
presentation, not the ~7x simulation deficit.
Kept behind kSynthesizeSwap rather than deleted: the 2026-09-18 symptom it
was built for (screen cycling between stale loading screen, black, and the
real scene) was diagnosed under the false premise above, so its actual
cause is still open.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -43,12 +43,35 @@ public class GameRenderer implements GLSurfaceView.Renderer {
|
||||
this._height = i2;
|
||||
}
|
||||
|
||||
// Task #47 instrumentation (2026-09-19, temporary). Settles a premise that
|
||||
// has been reasoned from since 2026-09-18 without ever being re-verified
|
||||
// live: that nativeOnResume runs the guest's persistent loop synchronously
|
||||
// here and NEVER returns, so GLSurfaceView's own automatic
|
||||
// post-onDrawFrame eglSwapBuffers stops firing. If that premise holds,
|
||||
// this logs exactly one line reading entries=1 exits=0 and then stays
|
||||
// silent forever. If the lines keep coming instead, onDrawFrame IS
|
||||
// returning, the framework IS also swapping, and that is the second
|
||||
// present of each observed pair.
|
||||
// System.nanoTime() is CLOCK_MONOTONIC on Android - the same clock the
|
||||
// native SWAPMARK lines use - so the two logs correlate directly.
|
||||
private static int drawEntries = 0;
|
||||
private static int drawExits = 0;
|
||||
private static long lastDrawReport = 0;
|
||||
|
||||
@Override // android.opengl.GLSurfaceView.Renderer
|
||||
public void onDrawFrame(GL10 gl10) {
|
||||
drawEntries++;
|
||||
long now = System.nanoTime();
|
||||
if (now - lastDrawReport > 1000000000L) {
|
||||
lastDrawReport = now;
|
||||
android.util.Log.i("mpcore_log", "GameRenderer: onDrawFrame entries=" + drawEntries
|
||||
+ " exits=" + drawExits + " t=" + now);
|
||||
}
|
||||
if (this.drawFrameListener != null) {
|
||||
this.drawFrameListener.onDrawFrame(gl10);
|
||||
} else {
|
||||
this.activity.getRunLoop().onRunLoopTick();
|
||||
}
|
||||
drawExits++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user