我對flatbuffers很新穎,並且相信我正確地按照教程進行了修改,但將其修改爲我的需要,但無法爲我的生活找出原因,我得到此錯誤: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
三次
Flatbuffers模式:
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'都應該是相同的類型。 – Aardappel
當您嘗試此操作時,您處於調試模式(斷言)嗎?因爲當我嘗試傳遞一個結構向量到'CreateVector'時,我得到'錯誤:靜態斷言失敗:T必須是標量類型'。 – Aardappel