【发布时间】:2017-02-26 12:28:38
【问题描述】:
我对 flatbuffers 很陌生,相信我正确地遵循了本教程,但根据我的需要对其进行了修改,但我终其一生都无法弄清楚为什么会出现此错误:
error: could not convert ‘_Positions’ from ‘flatbuffers::Offset<flatbuffers::Vector<Renderer::Import::Vec3> >’ to ‘flatbuffers::Offset<flatbuffers::Vector<const Renderer::Import::Vec3*> >’
_Materials, _Faces);
此外,我刚刚注意到它还抛出了error: static assertion failed: T must be a scalar type 三次
平面缓冲区架构:
namespace Renderer.Import;
struct Vec3 {
...
}
struct Face {
...
}
struct Material{
...
}
table Mesh{
Name:string;
Positions:[Vec3];
Normals:[Vec3];
Materials:[Material];
Faces:[Face];
}
C++ 代码:
flatbuffers::FlatBufferBuilder builder(4096);
std::vector<Renderer::Import::Vec3> Normals;
// Populate
std::vector<Renderer::Import::Vec3> Positions;
// Populate
std::vector<Renderer::Import::Material> Materials;
// Populate
std::vector<Renderer::Import::Face> Faces;
// Populate
auto _Name = builder.CreateString(shapes[0].name);
auto _Normals = builder.CreateVector(Normals);
auto _Positions = builder.CreateVector(Positions);
auto _Materials = builder.CreateVector(Materials);
auto _Faces = builder.CreateVector(Faces);
// Errors with `_Position` argument, but maybe the other three are incorrect too
auto mesh = Renderer::Import::CreateMesh(builder, _Name, _Positions, _Normals, _Materials, _Faces);
任何关于这个问题的帮助将不胜感激
【问题讨论】:
-
请注意,您粘贴的错误过滤掉了一些字符,所以很难说问题是什么..您可以重新粘贴为代码块吗?您的架构和代码对我来说看起来是正确的。
_Positions和CreateMesh的第三个参数应该是相同的类型。 -
您在尝试此操作时是否处于调试模式(断言开启)?因为当我尝试将结构向量传递给
CreateVector时,我得到error: static assertion failed: T must be a scalar type。
标签: c++ flatbuffers