ADDicting ADDicting - 1 year ago 100
iOS Question

How to solve SceneKit double not supported error?

I have been looking into SceneKit for iOS over the past couple of days. I came across an issue when trying to create custom geometry. Whenever I tried to display the geometry, it would not draw, and show me this error during runtime.

SceneKit: error, C3DRendererContextSetupResidentMeshSourceAtLocation - double not supported

I created a playground targeting iOS to test a more simple example of custom geometry, and looked into this question about custom geometry using swift vs objective c.

I tried another project using objective c and still received the same error message.

The error does not appear when targeting the desktop on either the playground or a full project, and the geometry draws correctly. Only when targeting iOS does the error message occur.

import SceneKit
import QuartzCore // for the basic animation
import XCPlayground // for the live preview

// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene

// start a live preview of that view
XCPShowView("The Scene View", sceneView)

// default lighting
sceneView.autoenablesDefaultLighting = true

// a camera
var camera = SCNCamera()
var cameraNode = SCNNode() = camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)

// create geometry
var verts = [SCNVector3(x: 0,y: 0,z: 0),SCNVector3(x: 1,y: 0,z: 0),SCNVector3(x: 0,y: 1,z: 0)]

let src = SCNGeometrySource(vertices: &verts, count: 3)
let indexes: [CInt] = [0, 1, 2]

let dat = NSData(
bytes: indexes,
length: sizeof(CInt) * countElements(indexes)
let ele = SCNGeometryElement(
data: dat,
primitiveType: .Triangles,
primitiveCount: 1,
bytesPerIndex: sizeof(CInt)
let geo = SCNGeometry(sources: [src], elements: [ele])

let nd = SCNNode(geometry: geo)

Here is the code I am using in the playground to draw a triangle. The same code is used when targeting the desktop.

How can I fix this and display the geometry for iOS?

Answer Source

My guess would be an issue with SCNVector3 being defined in terms of CGFloat for desktop (which can be either 32 or 64 bit depending on the host) and Float for iOS devices -- the iOS Simulator platform (which is what you get when targeting iOS in a playground) is neither quite like a device nor quite like OS X. Filing a bug with Apple would be a good idea.

In the meantime, a good workaround might be to use the more detailed initializer (that starts with init(data:semantic:...) to create your geometry source.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download