Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

示例页面第二次进入时无法显示(黑屏) #89

Open
chenjm1109 opened this issue Oct 10, 2022 · 3 comments · May be fixed by #165
Open

示例页面第二次进入时无法显示(黑屏) #89

chenjm1109 opened this issue Oct 10, 2022 · 3 comments · May be fixed by #165
Labels
bug Something isn't working reproduce-able

Comments

@chenjm1109
Copy link

浏览web版本的示例程序时,以loader/gltf为例,第一次进入可以正常显示,退出到主页后再次进入,就没有任何显示了。似乎其它加载外部模型的loader页面也有这样的情况。

@wasabia
Copy link
Owner

wasabia commented Oct 12, 2022

@chenjm1109
已复现,有时间看一下

@Ahmadre
Copy link

Ahmadre commented Nov 20, 2022

I assume this has to do with disposing resources.

@shixiong2333
Copy link

shixiong2333 commented Dec 18, 2024

I encountered the same problem.
I understand the main reason is that the file with the same path is loaded twice.
The following is my sample code。

    var stlLoader = STLLoader(null);
    var meshGeometry1 = await stlLoader.loadAsync("assets/ClosedArea.stl");
    var meshGeometry2 = await stlLoader.loadAsync("assets/ClosedArea.stl");

When debugging, I found that FileLoader helped me deal with the resource path problem. I understand that the code here is for http to parse the file normally.
https://github.com/wasabia/three_dart/blob/main/lib/three3d/loaders/file_loader.dart#L167-L172

// load assets file TODO
if (url.startsWith("assets")) {
        url = "assets/$url";
      }
      
http.Response response = await http.get(Uri.parse(url ));

This will cause the subsequent loader to be unable to remove the corresponding url
https://github.com/wasabia/three_dart/blob/main/lib/three3d/loaders/file_loader.dart#L191
image
Then the next time you load, it will think it is still loading and will not be able to return the correct geometry buffer.
image
I temporarily changed it to the following code and it worked.

      // load assets file TODO
      var httpUrl = url;
      if (httpUrl.startsWith("assets")) {
        httpUrl = "assets/$httpUrl";
      }

      http.Response response = await http.get(Uri.parse(httpUrl));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduce-able
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants