Kotlin, smart cast is impossible because of complex expression

Since mMeshes is a var property, it can change between the assignment of mutableListOf(AiMesh()) and the usage in pScene.mMeshes[0], meaning that it is not guaranteed to be not-null at the use site.

The compiler enforces null-safety, treating pScene.mMeshes as nullable MutableList<AiMesh>? and not allowing you to use it as MutableList<AiMesh> (i.e. it cannot safely perform a smart cast).

To fix that, you can simply make a non-null assertion:

val pMesh = pScene.mMeshes!![0]

Or just reuse the value you put into the list:

val pMesh = AiMesh()
pScene.mMeshes = mutableListOf(mesh)
// use `pMesh` below

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)