Error when creating Vector of structs

31 views
Skip to first unread message

Peter Taylor

unread,
Feb 26, 2017, 2:53:20 PM2/26/17
to FlatBuffers
I am very new to flatbuffers and believe I am following the tutorial correctly but modifying it to my needs, but cannot for the life of me work out why i'm getting this error:

     error: could not convert ‘_Positions’ from ‘flatbuffers::Offset<flatbuffers::Vector<Renderer::Import::Vec3> >’ to ‘flatbuffers::Offset<flatbuffers::Vector<const Renderer::Import::Vec3*> >’
                                            _Materials, _Faces);

in addition, I've just noticed it's also throwing ` error: static assertion failed: T must be a scalar type` thrice


Flatbuffers Schema:

  
 
   
namespace Renderer.Import;
   
struct Vec3 {
   
...
   
}
   
   
   
struct Face {
   
...
   
}
   
struct Material{
   
...
   
}
   
    table
Mesh{
     
Name:string;
     
Positions:[Vec3];
     
Normals:[Vec3];
     
Materials:[Material];
     
Faces:[Face];
   
}



C++ Code: 


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

Wouter van Oortmerssen

unread,
Feb 26, 2017, 3:53:47 PM2/26/17
to Peter Taylor, FlatBuffers
Use CreateVectorOfStructs instead of CreateVector when used with structs.

The API is to blame for accepting a vector of structs with CreateVector, we'll have to fix that.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages