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

Memory-block analysis - 3d program terminated unexpectedly

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

我尝试使用的是这个命令: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     [=10=]
37       0     [=10=]
38       0     [=10=]
39       0     [=10=]
40       1     data type
41       2     cmp count
42       0     normalize flag
43       4     string length
44       117   u 
45       118   v
46       0     [=10=]
47       0     [=10=]
-- 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

设置您的 header,然后:

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")

设置您的属性信息并最终转储两个 vertex/index 数据,您在其中使用偏移量 48108。似乎整个转储的偏移量是正确的(如果我的评论没有遗漏任何东西)所以我要在这里猜测:

  • 您正在使用 unsigned byte 作为 uv 坐标的数据类型而不是 float,也许这是一个错误?
  • 你的顶点位置真的很可疑,也许你的 for 循环使用了错误的 offsets/memory 位置?

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

编辑:您似乎被迫为顶点属性使用正确的数据类型,一个很好的提示是考虑 Mesh 吸气剂的 return 类型,即:

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 函数来详细了解您遇到的错误类型