Title: SceneKit custom geometry produces “double not supported” / “invalid vertex format” runtime error
Tags: swift;scenekit
Question: I don't understand what's wrong with the following code:

```class Terrain {

    private class func createGeometry () -&gt; SCNGeometry {

        let sources = [
            SCNGeometrySource(vertices:[
                SCNVector3(x: -1.0, y: -1.0, z:  0.0),
                SCNVector3(x: -1.0, y:  1.0, z:  0.0),
                SCNVector3(x:  1.0, y:  1.0, z:  0.0),
                SCNVector3(x:  1.0, y: -1.0, z:  0.0)], count:4),
            SCNGeometrySource(normals:[
                SCNVector3(x:  0.0, y:  0.0, z: -1.0),
                SCNVector3(x:  0.0, y:  0.0, z: -1.0),
                SCNVector3(x:  0.0, y:  0.0, z: -1.0),
                SCNVector3(x:  0.0, y:  0.0, z: -1.0)], count:4),
            SCNGeometrySource(textureCoordinates:[
                CGPoint(x: 0.0, y: 0.0),
                CGPoint(x: 0.0, y: 1.0),
                CGPoint(x: 1.0, y: 1.0),
                CGPoint(x: 1.0, y: 0.0)], count:4)
        ]

        let elements = [
            SCNGeometryElement(indices: [0, 2, 3, 0, 1, 2], primitiveType: .Triangles)
        ]

        let geo = SCNGeometry(sources:sources, elements:elements)

        let mat = SCNMaterial()
        mat.diffuse.contents = UIColor.redColor()
        mat.doubleSided = true
        geo.materials = [mat, mat]


        return geo
    }

    class func createNode () -&gt; SCNNode {

        let node = SCNNode(geometry: createGeometry())
        node.name = "Terrain"
        node.position = SCNVector3()
        return node
    }
}
```

I use it as follows:

```   let terrain = Terrain.createNode()
   sceneView.scene?.rootNode.addChildNode(terrain)
```

But get:

```2016-01-19 22:21:17.600 SceneKit: error, C3DRendererContextSetupResidentMeshSourceAtLocation - double not supported
2016-01-19 22:21:17.601 SceneKit: error, C3DSourceAccessorToVertexFormat - invalid vertex format
/BuildRoot/Library/Caches/com.apple.xbs/Sources/Metal/Metal-588-992-3154/Framework/MTLVertexDescriptor.mm:761: failed assertion `Unused buffer at index 18.'
```


Here is the accepted answer: The issue is that the geometry is expecting ```float``` components but you’re giving it ```double```s—CGPoint’s components are CGFloat values, which are typedef’d to ```double``` on 64-bit systems. Unfortunately, the SCNGeometrySource ```…textureCoordinates:``` initializer insists on CGPoints, so you can’t use that; the workaround I found was to create an NSData wrapping an array of SIMD float vectors, then use the much longer ```data:semantic:etc:``` initializer to consume the data. Something like this should do the trick:

```let coordinates = [float2(0, 0), float2(0, 1), float2(1, 1), float2(1, 0)]
let coordinateData = NSData(bytes:coordinates, length:4 * sizeof(float2))
let coordinateSource = SCNGeometrySource(data: coordinateData,
                                     semantic: SCNGeometrySourceSemanticTexcoord,
                                  vectorCount: 4,
                              floatComponents: true,
                          componentsPerVector: 2,
                            bytesPerComponent: sizeof(Float),
                                   dataOffset: 0,
                                   dataStride: sizeof(float2))
```

Comment for this answer: By using the way you set the texture coord (or by removing texturecoord in the elements) my code does not break anymore. Good. But it draws nothing on screen. I asked this specific question here: http://stackoverflow.com/questions/34897040/scenekit-custom-geometry-does-not-show-up


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:01/19/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<swift><scenekit>', 'Title': 'SceneKit custom geometry produces “double not supported” / “invalid vertex format” runtime error', 'ViewCount': 534, 'id': 34888231, 'user_AboutMe': '<p>My passion is to quickly materialize ideas: one of my latest pet project is ”Gas Discount” ⛽️ to get 20% off on your gas (<a href="https://apps.apple.com/nl/app/carburant-discount/id1465235480" rel="nofollow noreferrer">https://apps.apple.com/nl/app/carburant-discount/id1465235480</a>) (Swift) Released v1 @ xmas 2019 (ads+freemium model). Writing v2 in Dart/Flutter for early 2022.</p>\n<p>Currently, and since 2019: VP digital, CTO &amp; CPO at Olenergies ( LiFP connected batteries) where I develop anEMS IoT ecosystem from crash that comprises — 1) an IoT platform that connects DERs and optimizes the energy of thousands batteries across the world (Azure / MongoDB / TSI / InfluxDB / PostgreSQL / MERN / GraphQL / Docker / WSS / MQTT / IoT Hub / DPS) — 2) a Linux-based smart controller (Beaglebone / NodeJS) and custom ESP32 PCB (ESP32 / CPP / FreeRTOS) that connects to batteries BMS (thru CANbus &amp; RS485) and charger/inverter (thru MODbus). w/ automatic updates and —\xa03) an iOS + Android BLE app to control the control everything (Flutter 2 / Dart).</p>\n<p>2014 - 2016: CTO / CPO at Presstalis/ZEENS. I created a brand new B2C digital press service that exposes all journals &amp; mags published in France since 1947 via an all-you-can-eat subscription-based model on iPad (See video here <a href="https://stephanedeluca.com/zeens.php" rel="nofollow noreferrer">https://stephanedeluca.com/zeens.php</a>). I also designed and developed mobile-to-store and digital newsstand apps which includes social networking and bringing innovative BM to the press industry (50 % discount on mags) + in-store purchase of journals &amp; show tickets in partnership with Ville de Paris, JCDecaux, Mediakiosk, FNAC/France Billet, Logista and Presstalis)</p>\n<p>2009 - 2014: member of the Executive Committee of the RIAM government funding organisation (CNC/OSEO): financing of innovative projects in the movie and computer-related industries at large (11M€/year).</p>\n<p>2010 - 2014: VP Products and CTO at LeKiosque.fr, focused on the digital magazine distribution where I designed the first ever 3D newsstand for iPad, ranking #1 grossing app for iPad in France with more 1.5M downloads!</p>\n<p>2009 - 2010, acted as COO for Mimesis Republic and industrialized the production (MMO/social network &amp; apps).</p>\n<p>In 2009, I published Santa-Claus for iPhone on AppStore, introducing for the 1st time the 3D parallax effect since natively integrated by Apple in iOS!</p>\n<p>2007 - 2009, I was the MobiLuck.com CTO (geolocalized social network for mobiles). This LBS friends finder service displays 35M pages/month and has attracted more than 1.2M users (Q2 2009) since its launch in August 2007 and currently recruits an average of 5K users per day as per the current trend and we see our traffic doubling every quarter!</p>\n<p>From 2003, I was the In-Fusio Advanced Technology Manager where I created mobile phone massive cross-platform multi-player technology &amp; service.</p>\n<p>Before, I\'ve been in the video game industry for 10y where I successively developed titles, created &amp; sold realtime 3D technologies &amp; finally took in charge a business unit of Kalisto (IPO in 1999)</p>\n<p>Get in touch @ +33 6 13 510 966 / stephane@deluca.biz</p>\n', 'user_AccountId': 246850.0, 'user_DisplayName': 'Stéphane de Luca', 'user_Reputation': 12022.0, 'user_Views': 832.0, 'user_id': 2525948.0}}