Martin Gagnon
11/28/2019, 9:37 PM1.3.60
, my iOS application crashes with one of the following assert from memory.cpp:
- RuntimeAssert "Must be positive"
- RuntimeAssert "cycle collector shall only work with single object containers"
Sadly, I am not able to pinpoint or reproduce this issue with sample code. The only stack I have is the GarbageCollector failing.
Any hints on what or how to investigate would be much appreciated.
More info in the thread.Martin Gagnon
11/28/2019, 9:37 PMobject DataConverter {
@ExperimentalUnsignedTypes
fun convert(data: NSData): ByteArray {
val memScopedData = memScoped { data }
val byteArray = ByteArray(memScopedData.length.toInt()).apply {
usePinned {
memcpy(it.addressOf(0), memScopedData.bytes, memScopedData.length)
}
}
return byteArray
}
@ExperimentalUnsignedTypes
fun convert(byteArray: ByteArray): NSData {
return memScoped {
NSData.create(bytesNoCopy = allocArrayOf(byteArray),
length = byteArray.size.toULong())
}
}
}
Swift code:
extension Data {
func toKotlinByteArray() -> KotlinByteArray {
return DataConverter().convert(data: self)
}
}
extension KotlinByteArray {
func toNSData() -> Data {
return DataConverter().convert(byteArray: self)
}
}
olonho
11/29/2019, 5:31 AMval memScopedData = memScoped { data }
is pretty much meaningless. What are you tryng to do here?olonho
11/29/2019, 5:42 AMobject DataConverter {
@ExperimentalUnsignedTypes
fun convert(data: NSData): ByteArray {
val byteArray = ByteArray(data.length.toInt()).apply {
usePinned {
memcpy(it.addressOf(0), data.bytes, data.length)
}
}
return byteArray
}
@ExperimentalUnsignedTypes
fun convert(byteArray: ByteArray): NSData {
return byteArray.usePinned {
NSData.create(bytes = it.addressOf(0),
length = byteArray.size.toULong())
}
}
}
olonho
11/29/2019, 5:42 AMMartin Gagnon
11/29/2019, 1:07 PM/Users/teamcity/buildAgent/work/4d622a065c544371/runtime/src/main/cpp/Memory.cpp:1091: runtime assert: Must be positive
olonho
11/29/2019, 3:59 PMMartin Gagnon
11/29/2019, 8:22 PMJoakimForslund
11/30/2019, 12:47 PM