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

Memory 内存块分析-3d程序意外终止,memory,data-structures,3d,agk-basic,Memory,Data Structures,3d,Agk Basic,我尝试在虚拟现实中加入一个网格 我尝试使用以下命令: 我插入的数据是以下数据: 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 co

我尝试在虚拟现实中加入一个网格

我尝试使用以下命令:

我插入的数据是以下数据:

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")
要设置属性信息并最终转储顶点/索引数据,请使用偏移量
48
108
。看起来整个转储的偏移量是正确的(如果我的评论没有遗漏任何内容),所以我在这里猜测:

  • 您正在使用
    无符号字节
    作为uv坐标的数据类型,而不是
    浮点
    ,这可能是个错误
  • 顶点的位置非常可疑,可能for循环使用了错误的偏移/内存位置
这只是猜测,通过查看内存转储不容易找到bug,如果您发布实际代码,我可能会做出更好的假设

编辑:似乎强制您为顶点属性使用正确的数据类型,一个好的提示是考虑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 )

此外,请确保您使用这些函数来了解更多有关错误类型的信息

图像上的uv坐标为x和y。图像坐标是alwals整数。但文件上说,除了颜色以外,一切都是浮动的。我认为这里的文档是错误的。但我会检查这个。我读过,可以确认它一定是一个浮点值。酷,那么,我的猜测是对的吗?这就是您收到错误代码1的原因吗?是的,是的。很高兴我的猜测是对的,我很幸运。略加修改我的答案