3

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

Any help on this issue would be greatly appreciated

user181782
  • 45
  • 1
  • 8
  • Notice that the error you pasted filtered out some characters, so it is hard to say what the problem is.. can you re-paste as a code block? your schema and code look otherwise correct to me. Both `_Positions` and the 3rd arg to `CreateMesh` should be the same type. – Aardappel Feb 26 '17 at 17:45
  • Were you in debug mode (assertions on) when you tried this? Because when I try passing a vector of structs to `CreateVector`, I get `error: static assertion failed: T must be a scalar type`. – Aardappel May 11 '17 at 00:58

1 Answers1

3

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.

Aardappel
  • 5,559
  • 1
  • 19
  • 22
  • It should give: `error: static assertion failed: T must be a scalar type` – Aardappel May 11 '17 at 00:59
  • Doesn't this then mean you would not be able to use the auto-generated `Mesh` class to read your `Mesh` tables because it is expecting the results of `CreateVector` and not the results of `CreateVectorOfStructs`? – mcmcc Jan 31 '18 at 19:53
  • @mcmcc Where does it expect the result of CreateVector? Note that this commit may have fixed some of this: https://github.com/google/flatbuffers/commit/fee9afd80b6358a63b92b6991d858604da524e2b If not, please file an issue on github – Aardappel Jan 31 '18 at 23:48
  • I'm somewhat new to flatbuffers and I was confused about the (inoperability) consequences of choosing `CreateVectorOfStructs` vs `CreateVector`. Now I think it was a misunderstanding on my part. And yes, it looks like that fix might relieve a lot of confusion and simplify a lot of code. Any idea of when that will appear in a tagged release? – mcmcc Feb 02 '18 at 04:50
  • I have no idea when the next tagged release will be... I can look into it. – Aardappel Feb 02 '18 at 15:13