title: Flatbuffers: Access Violation: Endian Scalar
body: <p><a href="https://pastebin.com/1cZ8M5Zk" rel="nofollow noreferrer">https://pastebin.com/1cZ8M5Zk</a></p>
  
  <p>Schema:</p>
  
  <pre><code>/* 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;
  */
  </code></pre>
  
  <p>Building:</p>
  
  <pre><code>//....
  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&lt;uint32_t&gt;(Indices);
  
  unsigned int h = 1024; //Hash of Name of Material
  
  std::vector&lt;flatbuffers::Offset&lt;VertexObject&gt;&gt; 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);
  //...
  </code></pre>
  
  <p>Loading:</p>
  
  <pre><code>auto test = GetModel(data);
  
  
  assert(test-&gt;Name());
  auto name = test-&gt;Name();
  
  assert(test-&gt;Meshes());
  auto FBMeshes = test-&gt;Meshes();
  
  
  for (unsigned int i = 0; i &lt; FBMeshes-&gt;size(); i++)
  {
      assert(FBMeshes-&gt;Get(i));
      auto FBMeshesIndex = FBMeshes-&gt;Get(i);
  
  
      //assert(FBMeshesIndex-&gt;MData());
  }
  </code></pre>
  
  <p>I get an Access Violation when trying to call a Table Vector in Flatbuffers. Included is the Schema, and Source Code. I believe it to be something to do with how the components serialized together for the MeshData Table, but I am unable to figure out where exactly. I get the Error when I try to run assert(FBMeshesIndex->MData()); which is Root->Vec:Tables()->Get(i)->Vec:Tables() of which contains several Vec of Structs.</p>
  
  <blockquote>
    <p>TestBed.exe!flatbuffers::ReadScalar(const void * p) Line 219    C++ Symbols loaded.
        TestBed.exe!flatbuffers::Table::GetOptionalFieldOffset(unsigned short field) Line 1866  C++ Symbols loaded.
        TestBed.exe!flatbuffers::Table::GetPointer(unsigned short field) Line 1878   C++ Symbols loaded.
        TestBed.exe!flatbuffers::Table::GetPointer(unsigned short field) Line 1885   C++ Symbols loaded.
        TestBed.exe!Resource::Model::VertexObject::MData() Line 180 C++ Symbols loaded.
        TestBed.exe!main() Line 147 C++ Symbols loaded.
        [External Code]     Annotated Frame</p>
  </blockquote>