flutter_scene icon indicating copy to clipboard operation
flutter_scene copied to clipboard

demo runs not smoothly on android

Open wangcker opened this issue 1 year ago • 7 comments

The demo program runs not smoothly and stutters on the Android system, but it run smoothly on the iOS system

android runs video:

https://github.com/user-attachments/assets/171e7477-208c-4c9b-a6c2-78f10b81e4ce

wangcker avatar Nov 05 '24 03:11 wangcker

the whole code :


import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_scene/camera.dart';
import 'package:flutter_scene/node.dart';

import 'package:flutter_scene/scene.dart';
import 'package:vector_math/vector_math.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
  double elapsedSeconds = 0;
  Scene scene = Scene();

  @override
  void initState() {
    createTicker((elapsed) {
      debugPrint("time ${elapsed.inMilliseconds.toDouble() / 1000}");
      setState(() {
        elapsedSeconds = elapsed.inMilliseconds.toDouble() / 1000;
      });
    }).start();

    Node.fromAsset('build/models/DamagedHelmet.model').then((model) {
      model.name = 'Helmet';
      scene.add(model);
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final painter = ScenePainter(
      scene: scene,
      camera: PerspectiveCamera(
        position: Vector3(sin(elapsedSeconds) * 2, 2, cos(elapsedSeconds) * 2),
        target: Vector3(0, 0, 0),
      ),
    );

    return MaterialApp(
      title: '我的 3D 应用',
      home: CustomPaint(painter: painter),
    );
  }
}

class ScenePainter extends CustomPainter {
  ScenePainter({required this.scene, required this.camera});
  Scene scene;
  Camera camera;

  @override
  void paint(Canvas canvas, Size size) {
    scene.render(camera, canvas, viewport: Offset.zero & size);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}

wangcker avatar Nov 05 '24 03:11 wangcker

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

kwill39 avatar Nov 06 '24 04:11 kwill39

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

no,the problem still exists , so change the flutter_scene ref from pub.dev.

wangcker avatar Nov 06 '24 13:11 wangcker

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

i fix it #43

wangcker avatar Nov 07 '24 08:11 wangcker

Some questions:

  • What Android device are you testing this out on?
  • Is it real hardware or a simulator?
  • Could you paste the full run log? Specifically, I'm interested in the line that says which Impeller backend is in use. For most devices, the Vulkan backend will be used, but for others we'll fall back to the OpenGLES 2 backend (which has different performance characteristics).

bdero avatar Nov 16 '24 01:11 bdero

  • it is hardware
  • testing on xiaomi 14 pro

it`s may be producted by memory leak

wangcker avatar Nov 25 '24 03:11 wangcker

Hi, I am using moto g power(2021), galaxy 20 FE. I am experiencing the same issue as wangsker. It seems there is memory leak and after running the example demo for 10 mins, the application crashes.

DionNam avatar Jan 24 '25 02:01 DionNam