在 Dart 中如何使用 true 返回值?

发布于 2024-12-27 16:17:54 字数 2188 浏览 5 评论 0原文

当我尝试执行下面的代码时,出现以下错误。

未捕获类型错误:对象 true 没有方法“dartObjectLocalStorage$getter”

我在 Dart 编辑器版本 0.1.0.201201150611 Build 3331 中启动了一个 Web 应用程序。以下是单独 dart 文件的完整代码。下面注释了导致错误的 if 语句。

#import('dart:html');

class Test3D {
  CanvasElement theCanvas;
  WebGLRenderingContext gl;

  static String vertexShaderSrc = """
    attribute vec3 aVertexPosition;

    void main(void) {
      gl_Position = vec4(aVertexPosition, 1.0); 
    }  
  """;

  Test3D() {
  }

  void run() {   
    write("Hello World!");

    // Set up canvas
    theCanvas = new Element.html("<canvas></canvas>");
    theCanvas.width = 100;
    theCanvas.height = 100;
    document.body.nodes.add(theCanvas);

    // Set up context
    gl = theCanvas.getContext("experimental-webgl");
    gl.clearColor(0.5, 0.5, 0.5, 1.0);
    gl.clear(WebGLRenderingContext.COLOR_BUFFER_BIT);

    WebGLShader vertexShader = gl.createShader(WebGLRenderingContext.VERTEX_SHADER);
    gl.shaderSource(vertexShader, vertexShaderSrc);
    gl.compileShader(vertexShader);

    // Adding this line results in the error: Uncaught TypeError: Object true has no method 'dartObjectLocalStorage$getter
    var wasSuccessful = gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS);   
  }

  void write(String message) {
    // the HTML library defines a global "document" variable
    document.query('#status').innerHTML = message;
  }
}

void main() {
  new Test3D().run();
}

我真的很热衷于 dart,并且非常感谢您在这方面能给我的任何帮助。

这是错误的控制台输出:

Uncaught TypeError: Object true has no method 'dartObjectLocalStorage$getter'
htmlimpl0a8e4b$LevelDom$Dart.wrapObject$member
htmlimpl0a8e4b$WebGLRenderingContextWrappingImplementation$Dart.getShaderParameter$member
htmlimpl0a8e4b$WebGLRenderingContextWrappingImplementation$Dart.getShaderParameter$named
unnamedb54266$Test3D$Dart.run$member
unnamedb54266$Test3D$Dart.run$named
unnamedb54266$main$member
RunEntry.isolate$current
isolate$Isolate.run
isolate$IsolateEvent.process
isolate$doOneEventLoopIteration
next
isolate$doRunEventLoop
isolate$runEventLoop
RunEntry
(anonymous function)

I get the following error when I try to execute the code below.

Uncaught TypeError: Object true has no method 'dartObjectLocalStorage$getter'

I started a Web Application in Dart Editor Version 0.1.0.201201150611 Build 3331. Here is the complete code for the lone dart file. The if statement that results in the error is commented below.

#import('dart:html');

class Test3D {
  CanvasElement theCanvas;
  WebGLRenderingContext gl;

  static String vertexShaderSrc = """
    attribute vec3 aVertexPosition;

    void main(void) {
      gl_Position = vec4(aVertexPosition, 1.0); 
    }  
  """;

  Test3D() {
  }

  void run() {   
    write("Hello World!");

    // Set up canvas
    theCanvas = new Element.html("<canvas></canvas>");
    theCanvas.width = 100;
    theCanvas.height = 100;
    document.body.nodes.add(theCanvas);

    // Set up context
    gl = theCanvas.getContext("experimental-webgl");
    gl.clearColor(0.5, 0.5, 0.5, 1.0);
    gl.clear(WebGLRenderingContext.COLOR_BUFFER_BIT);

    WebGLShader vertexShader = gl.createShader(WebGLRenderingContext.VERTEX_SHADER);
    gl.shaderSource(vertexShader, vertexShaderSrc);
    gl.compileShader(vertexShader);

    // Adding this line results in the error: Uncaught TypeError: Object true has no method 'dartObjectLocalStorage$getter
    var wasSuccessful = gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS);   
  }

  void write(String message) {
    // the HTML library defines a global "document" variable
    document.query('#status').innerHTML = message;
  }
}

void main() {
  new Test3D().run();
}

I'm really keen on dart and would appreciate any help you could give me on this.

Here is the console output for the error:

Uncaught TypeError: Object true has no method 'dartObjectLocalStorage$getter'
htmlimpl0a8e4b$LevelDom$Dart.wrapObject$member
htmlimpl0a8e4b$WebGLRenderingContextWrappingImplementation$Dart.getShaderParameter$member
htmlimpl0a8e4b$WebGLRenderingContextWrappingImplementation$Dart.getShaderParameter$named
unnamedb54266$Test3D$Dart.run$member
unnamedb54266$Test3D$Dart.run$named
unnamedb54266$main$member
RunEntry.isolate$current
isolate$Isolate.run
isolate$IsolateEvent.process
isolate$doOneEventLoopIteration
next
isolate$doRunEventLoop
isolate$runEventLoop
RunEntry
(anonymous function)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2025-01-03 16:17:54

该错误表明在代码中的某个位置,通过布尔值 true 访问了“dartObjectLocalStorage”字段。给定的代码片段不包含此标识符,因此可能不对错误负责。
错误报告可能给出了错误的行号(甚至可能给出了错误的文件)。

要调试此问题:

  • 尝试在代码中找到对“dartObjectLocalStorage”的引用。
  • 尝试在生成的代码中找到对“dartObjectLocalStorage$getter”的引用。
  • 在虚拟机上运行或使用不同的编译器进行编译(frogc 与 dartc)。

祝你好运。

The error indicates that somewhere in your code the field 'dartObjectLocalStorage' is accessed on the boolean true. The given code-snippet does not contain this identifier and is thus probably not responsible for the error.
It could be that the error-reporting gives the wrong line number (potentially even the wrong file).

To debug this:

  • try to find a reference to 'dartObjectLocalStorage' in your code.
  • try to find a reference to 'dartObjectLocalStorage$getter' in the generated code.
  • run on the VM or compile with a different compiler (frogc vs dartc).

good luck.

も星光 2025-01-03 16:17:54

根据 WebGLRenderingContext 的文档,如果您知道该对象,则返回类型是 Object是 bool 你可以将它用作 bool 或动态

var v=gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS)

或更明确

var v=gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS).dynamic

,然后在条件语句中使用它。还可以尝试使用 frogc 来编译它,而不是在 JavaScript 编译器中构建,它通常会导致更好的错误。

According to the documentation for WebGLRenderingContext the return type is Object, if you know the object is bool you can just use it as a bool or dynamic

var v=gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS)

or more explicitly

var v=gl.getShaderParameter(vertexShader, WebGLRenderingContext.COMPILE_STATUS).dynamic

and then use it in your conditional statement. Also try compiling it with frogc rather than the build in JavaScript compiler, it usually results in better errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文