无法访问混乱中的动画属性
我正在尝试为 Clutter 中的演员设置动画,但是当我输入存在的属性时,出现了问题。
actor.animate( AnimationMode.LINEAR, 400, scale_x:2);
给我这个错误
混乱警告 **:无法绑定属性“\x83\xec\u0014\x89\xc6e\xa1\u000c”:“ClutterTexture”类型的对象没有此属性
对我来说看起来像 Unicode 字符。 但是,当我输入一个不存在的属性时,
actor.animate( AnimationMode.LINEAR, 400, thisdoesntwork:2);
我会收到一个更有意义的错误
混乱警告 **:无法绑定属性“thisdoesntwork”:“ClutterTexture”类型的对象没有此属性
当我尝试这种替代方法时,我遇到了完全相同的问题:
actor.animate( AnimationMode.LINEAR, 400, "scale-x", 2);
为什么实际存在的所有属性都会转换为一些混乱,我该怎么做才能让它发挥作用?
I am trying to animate an actor in Clutter, but when I enter a property that exists, something goes wrong.
actor.animate( AnimationMode.LINEAR, 400, scale_x:2);
gives me this error
Clutter-WARNING **: Cannot bind property '\x83\xec\u0014\x89\xc6e\xa1\u000c': objects of type 'ClutterTexture' do not have this property
Looks like Unicode-characters to me.
However, when I enter a property that does NOT exist
actor.animate( AnimationMode.LINEAR, 400, thisdoesntwork:2);
I get an error that makes much more sense
Clutter-WARNING **: Cannot bind property 'thisdoesntwork': objects of type 'ClutterTexture' do not have this property
I get the exact same problem when I try this alternative approach:
actor.animate( AnimationMode.LINEAR, 400, "scale-x", 2);
How come all properties that actually exist get converted to some mess, and what can I do to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 2.0 作为值,而不是 2。2 是整数,2.0 是双精度数。 Vala 无法为可变参数方法提供类型安全,因此您必须小心。
至于为什么您会看到存在的属性的行为,我的猜测是它与 2 是(32 位)整数而 2.0 是(64 位)双精度这一事实有关。这稍微简化了事情,我不知道你对 C 有多少经验(可能不是很多,因为这是来自动态类型语言的人会犯的错误),但是......混乱(嗯,va_arg) 需要一个 double,因此它解析 64 位数据,但您只提供了 32 位,因此包含下一个参数 (NULL) 的前 32 位。现在,当它开始尝试解析下一个参数时,它从错误的位置开始(参数中的 32 位),因此您会得到 NULL 的剩余部分以及堆栈上发生的任何垃圾的一部分......不出所料,这并不只是 32 位的 0,因此当 Clutter 测试刚刚读取的值是否为 == NULL 时,结果并非如此,并且 Clutter 认为它被赋予了一个指向以 null 结尾的字符数组的指针(这就是 C 语言中字符串的表示方式)。它读取该位置的数据(恰好是 \x83\xec\u0014\x89\xc6e\xa1\u000c),并检查是否存在具有该名称的属性。没有,所以它会发出您看到的错误消息。
现在,如果您切换到使用不存在的属性,Clutter 将解析参数(属性的名称),注意到它不存在(就像上面的第二个属性一样),并发出一个错误。
You should be using 2.0 for the value, not 2. 2 is an integer, 2.0 is a double. Vala can't provide type safety for variadic methods, so you have to be careful.
As for why you're seeing the behavior you are for properties which exist, my guess is it has to do with the fact that 2 is a (32-bit) integer and 2.0 is a (64-bit) double. This is simplifying things a bit, and I don't know how much experience you have with C (probably not a lot, since this is the sort of mistake someone coming from a dynamically typed language would make), however... Clutter (well, va_arg) expects a double so it parses 64 bits of data, but you only provided 32 bits, so the first 32-bits of the next argument (NULL) are included. Now, when it starts trying to parse the next argument it starts from the wrong location (32-bits into the argument), so you get the the remainder of NULL and part of whatever garbage happened to be on the stack... Unsuprisingly, that doesn't just so happen to be 32-bits of 0s so when Clutter tests to see if the value it just read == NULL it isn't and Clutter thinks it's been given a pointer to an null-terminated array of characters (which is how strings are represented in C). It reads the data at that location, which just so happens to be \x83\xec\u0014\x89\xc6e\xa1\u000c, and checks to see if there is a property with that name. There isn't, so it emits the error message you saw.
Now, if you switch to using a property which doesn't exist, Clutter will parse the argument (the name of the property), notice that it doesn't exist (just like it did with the second property above), and emit an error.