内存块分析 - 3d 程序意外终止

标签 memory data-structures 3d agk-basic

我尝试将网格放入虚拟现实中。

我尝试使用的是这个命令:CreateObjectFromMeshMemblock

我插入的数据是这个数据:

Byte No  Value
0        3     vertice count (aka first)
1        0     vertice count
2        0     vertice count
3        0     vertice count
4        3     indices count (aka second)
5        0     indices count
6        0     indices count
7        0     indices count
8        2     attr count    (aka third)
9        0     attr count
10       0     attr count
11       0     attr count
12       20    vertex size (aka fourth)
13       0     vertex size (20 because x+y+z + uvx+uvy = 5 * 4bytes = 20)
14       0     vertex size
15       0     vertex size
16       48    vertex-data offset (aka fifth)
17       0     vertex-data offset
18       0     vertex-data offset
19       0     vertex-data offset
20       108   indices-data offset (aka sixth)
21       0     indices-data offset
22       0     indices-data offset
23       0     indices-data offset
-- header success, starting vertex attribute data --
24       0     data type
25       3     cmp count
26       0     normalize flag
27       12    string length
28       112   p
29       111   o
30       115   s
31       105   i
32       116   t
33       105   i
34       111   o
35       110   n
36       0     \0
37       0     \0
38       0     \0
39       0     \0
40       1     data type
41       2     cmp count
42       0     normalize flag
43       4     string length
44       117   u 
45       118   v
46       0     \0
47       0     \0
-- offset vertex data --
48       0
49       0
50       183
51       66

52       0
53       0
54       183
55       66

56       0
57       0
58       183
59       66

60       0
61       0
62       0
63       0

64       0
65       0
66       0
67       0
 -- next vertex --
68       0
69       0
70       183
71       189

72       0
73       0
74       183
75       66

76       0
77       0
78       183
79       66

80       0
81       0
82       0
83       0

84       0
85       0
86       0
87       0
-- next vertex --
88       0
89       0
90       183
91       189

92       0
93       0
94       183
95       189

96       0
97       0
98       183
99       66

100      0
101      0
102      0
103      0

104      0
105      0
106      0 
107      0 
            -- now starting indices --
108      0 first index 
109      0 first index 
110      0 first index
111      0 first index
112      1 second index
113      0 second index
114      0 second index
115      0 second index 
116      2 third index
117      0 third index
118      0 third index
119      0 third index

不幸的是,执行命令时程序被终止,错误代码为 1。

知道为什么吗?

最佳答案

通过分析您的数据,您似乎正在做:

SetMemblockInt(memblock,0,3) //3 vertices
SetMemblockInt(memblock,4,3) //3 indices
SetMemblockint(memblock,8,2) //2 attributes, pos+uv
SetMemblockInt(memblock,12,20) // number bytes per vertex
SetMemblockInt(memblock,16,48) // vertex-data offset
SetMemblockInt(memblock,20,108) // indices-data offset

设置标题,然后:

SetMemBlockInt(memblock,24,0x0C000300) // float, 3 components, no normalizing, position
SetMemblockString(memblock,28,"position")

SetMemBlockInt(memblock,40,0x04000201) // unsigned byte, 2 components, no normalizing, uv
SetMemblockString(memblock,44,"uv")

设置属性信息并最终转储顶点/索引数据,其中使用偏移量48108。看来整个转储的偏移量是正确的(如果我的审查没有遗漏任何内容),所以我将在这里猜测:

  • 您使用 unsigned byte 作为 uv 坐标的数据类型,而不是 float,也许这是一个错误?
  • 您的顶点位置确实很可疑,也许您的 for 循环使用了错误的偏移量/内存位置?

这只是猜测,仅通过查看内存转储并不容易找到错误,也许如果您发布实际代码我可以做出更好的假设

编辑:看来您被迫对顶点属性使用正确的数据类型,一个很好的提示是考虑 Mesh 的返回类型 setter/getter ,即:

float GetMeshMemblockVertexNormalX( memID, vertexIndex )
float GetMeshMemblockVertexNormalY( memID, vertexIndex )
float GetMeshMemblockVertexNormalZ( memID, vertexIndex )

float GetMeshMemblockVertexU( memID, vertexIndex )
float GetMeshMemblockVertexV( memID, vertexIndex )

float GetMeshMemblockVertexX( memID, vertexIndex )
float GetMeshMemblockVertexY( memID, vertexIndex )
float GetMeshMemblockVertexZ( memID, vertexIndex )

integer GetMeshMemblockVertexAlpha( memID, vertexIndex )
integer GetMeshMemblockVertexBlue( memID, vertexIndex )
integer GetMeshMemblockVertexGreen( memID, vertexIndex )
integer GetMeshMemblockVertexRed( memID, vertexIndex )

此外,请确保使用 Error函数来更多地了解您遇到的错误类型

关于内存块分析 - 3d 程序意外终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55640865/

相关文章:

three.js - 如何将自定义着色器 Material 添加到 Three.js 中的 obj 3D 对象

linux - 在 Linux 中为进程分配物理内存

python - 如何创建特定的二叉树?

algorithm - 具有快速随机访问的类堆数据结构?

javascript - 如何反转在​​ CylinderGeometry 对象中应用纹理的方向?

swift - 使用多边形三角剖分创建自定义几何体并在 SceneKit 中应用纹理坐标

memory - 缺少Prometheus容器级别的缓冲内存指标

c - 使用 memset() 函数及其如何影响内存块

memory - 如何检查 indices.memory.index_buffer_size 参数在 elasticsearch 中是否有效?

c++ - 关于使用链表在堆栈实现中的嵌套类