Flatbuffers:访问冲突:Endian Scalar

时间:2018-01-05 19:58:30

标签: c++ serialization binary flatbuffers

https://pastebin.com/1cZ8M5Zk

架构:

/* Model.fbs
namespace Resource.Model;

struct Vec3 {
x:float;
y:float;
z:float;
}

struct Vec2 {
x:float;
y:float;
}

table MeshData {
Position:[Vec3];
Normal:[Vec3];
TexCoords:[Vec2];
Tangent:[Vec3];
Bitangent:[Vec3];
}

table VertexObject {
MData:MeshData;
Indices:[uint];
MatNameHash:uint;
}

table Model {
Name:uint;
Meshes:[VertexObject];
}

root_type Model;
*/

大厦:

//....
auto a = builder.CreateVectorOfStructs(Positions);
auto b = builder.CreateVectorOfStructs(Normals);
auto c = builder.CreateVectorOfStructs(TexCoords);
auto d = builder.CreateVectorOfStructs(Tangents);
auto e = builder.CreateVectorOfStructs(Bitangents);

auto f = CreateMeshData(builder, a, b, c, d, e);


auto g = builder.CreateVector<uint32_t>(Indices);

unsigned int h = 1024; //Hash of Name of Material

std::vector<flatbuffers::Offset<VertexObject>> VO;
auto i = CreateVertexObject(builder, f, g, h);
auto i2 = CreateVertexObject(builder, f, g, h);

VO.push_back(i);
VO.push_back(i2);

auto j = builder.CreateVector(VO);
//...

装载:

auto test = GetModel(data);


assert(test->Name());
auto name = test->Name();

assert(test->Meshes());
auto FBMeshes = test->Meshes();


for (unsigned int i = 0; i < FBMeshes->size(); i++)
{
    assert(FBMeshes->Get(i));
    auto FBMeshesIndex = FBMeshes->Get(i);


    //assert(FBMeshesIndex->MData());
}

尝试在Flatbuffers中调用表向量时出现访问冲突。包括Schema和源代码。我认为这与组件为MeshData表序列化的方式有关,但我无法确定究竟在哪里。我尝试运行assert时遇到错误(FBMeshesIndex-&gt; MData());这是Root-&gt; Vec:Tables() - &gt; Get(i) - &gt; Vec:Tables()包含几个Stru的Vec。

  

TestBed.exe!flatbuffers :: ReadScalar(const void * p)第219行C ++已加载符号。       TestBed.exe!flatbuffers :: Table :: GetOptionalFieldOffset(unsigned short field)Line 1866 C ++已加载符号。       TestBed.exe!flatbuffers :: Table :: GetPointer(unsigned short field)Line 1878 C ++已加载符号。       TestBed.exe!flatbuffers :: Table :: GetPointer(unsigned short field)Line 1885 C ++已加载符号。       TestBed.exe!Resource :: Model :: VertexObject :: MData()第180行C ++加载符号。       TestBed.exe!main()第147行C ++已加载符号。       [外部代码]带注释的框架

1 个答案:

答案 0 :(得分:0)

代码看起来没问题,因此问题可能超出了显示的代码,data从构建到使用的方式。

name 1024的值是多少?是FBMeshes->size() 2?此外,您应该在访问之前在data上运行验证程序,以查看数据传递方式是否存在任何问题。