android renderscript信号7(sigbus),代码1(bus\ adraln),故障地址0x76f458b4 adreno 306,320

d4so4syb  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(780)

我在两个测试设备上遇到问题-三星galaxy j5、android 6.0.1、内核3.10.49-11903637、构建mmb29m.j510fnxxu2aqg3 gpu adreno 306和nexus 4-gpu adreno 320。我试图通过对位图进行两次过滤来计算位图的清晰度。使用原始位图的采样大小,大小小于64x64,以提高性能。同样的代码在三星galaxy s6、索尼xperia z3、三星galaxy tab 10.1(2016)、华为p10上运行良好。尝试改变输入参数,使用不同的图像,不同的系数,但在j5上总是崩溃。
更新:对于在其他设备上拍摄的照片,当旋转到纵向时,成功通过(高度大于宽度)。然而,在同一台设备上拍摄的照片,无论我如何旋转它们都会崩溃。

  1. val options = BitmapFactory.Options()
  2. options.inJustDecodeBounds = true
  3. BitmapFactory.decodeFile(imagePath, options)
  4. val imageSize = SizeT(options.outWidth, options.outHeight)
  5. val imageScale = imageSize.scaleToFitInSize( SizeT( 64, 64) )
  6. val imageScaledSize = imageSize.scale(imageScale.toDouble())
  7. options.inJustDecodeBounds = false
  8. options.inSampleSize = ImageUtils.calculateInSampleSize(imageSize, imageScaledSize, 1.0)
  9. val sourceBitmap = BitmapFactory.decodeFile(imagePath, options)
  10. var sobelScript: ScriptC_sobel? = null
  11. var inputAllocation: Allocation? = null
  12. var outputAllocation: Allocation? = null
  13. var intermediateAllocation: Allocation? = null
  14. var convolve3x3: ScriptIntrinsicConvolve3x3? = null
  15. var renderScript: RenderScript? = null
  16. val imageWidth = sourceBitmap.width
  17. val imageHeight = sourceBitmap.height
  18. renderScript = RenderScript.create(ApplicationContext.ApplicationContext())
  19. inputAllocation = Allocation.createFromBitmap(renderScript, sourceBitmap)
  20. val typeInBuilder = Type.Builder(renderScript, Element.F32_4(renderScript)).setX( imageWidth ).setY( imageHeight )
  21. // Allocation where to store the sum result (for output purposes)
  22. val coefficientsGx = floatArrayOf(-1f, 0f, 1f, -2f, 0f, 2f, -1f, 0f, 1f)
  23. val coefficientsGy = floatArrayOf(-1f, -2f, -1f, 0f, 0f, 0f, 1f, 2f, 1f)
  24. intermediateAllocation = Allocation.createTyped(renderScript, typeInBuilder.create())
  25. convolve3x3 = ScriptIntrinsicConvolve3x3.create(renderScript, Element.F32_4(renderScript))
  26. convolve3x3.setInput(inputAllocation)
  27. convolve3x3.setCoefficients(coefficientsGx)
  28. convolve3x3.forEach(intermediateAllocation)

在最后一行,程序崩溃,出现本机错误:

  1. ? D/NetworkController.MobileSignalController(0/2147483643): onSignalStrengthsChanged signalStrength=SignalStrength: 26 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x4 gsm|lte level=4
  2. 2302-2671/? D/NetworkController.MobileSignalController(0/2147483643): getMobileIconGroup(): 0
  3. 16440-17400/ A/libc: Fatal signal 7 (SIGBUS), code 1, fault addr 0x76f458b4 in tid 17400 (AsyncTask #4)
  4. 16440-17398/ A/libc: Fatal signal 7 (SIGBUS), code 1, fault addr 0x76f456d4 in tid 17398 (AsyncTask #4)
  5. 16440-17398/ I/libc: Another thread contacted debuggerd first; not contacting debuggerd.
  6. 16440-17399/ A/libc: Fatal signal 7 (SIGBUS), code 1, fault addr 0x76f45404 in tid 17399 (AsyncTask #4)
  7. 16440-17399/ I/libc: Another thread contacted debuggerd first; not contacting debuggerd.
  8. 16440-17396/ A/libc: Fatal signal 7 (SIGBUS) in tid 17396 (AsyncTask #4)
  9. 16440-17396/I/libc: Another thread contacted debuggerd first; not contacting debuggerd.
  10. 400-400/? A/DEBUG:************************************************
  11. 400-400/? A/DEBUG: Build fingerprint: 'samsung/j5xnltexx/j5xnlte:6.0.1/MMB29M/J510FNXXU2AQG3:user/release-keys'
  12. 400-400/? A/DEBUG: Revision: '4'
  13. 400-400/? A/DEBUG: ABI: 'arm'
  14. 400-400/? A/DEBUG: pid: 16440, tid: 17400, name: AsyncTask #4 >>> com.test.development <<<
  15. 400-400/? A/DEBUG: signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x76f458b4
  16. 400-400/? A/DEBUG: r0 0000003b r1 00000000 r2 b8ceb4a0 r3 76f458b4
  17. 400-400/? A/DEBUG: r4 76f458b4 r5 9b68a7f8 r6 b8ceb4a0 r7 00000000
  18. 400-400/? A/DEBUG: r8 0000003c r9 76f459a4 sl 76f458b4 fp 76f45a94
  19. 400-400/? A/DEBUG: ip b8cb3c14 sp 9b68a7b0 lr 00000001 pc 9cff66d8 cpsr 200f0030
  20. 400-400/? A/DEBUG: backtrace:
  21. 400-400/? A/DEBUG: #00 pc 0002d6d8 /system/lib/libRSCpuRef.so
  22. 400-400/? A/DEBUG: #01 pc 0002d68b /system/lib/libRSCpuRef.so (_ZN7android12renderscript32RsdCpuScriptIntrinsicConvolve3x38kernelF4EPK24RsExpandKernelDriverInfojjj+122)
  23. 400-400/? A/DEBUG: #02 pc 0001f1f5 /system/lib/libRSCpuRef.so
  24. 400-400/? A/DEBUG: #03 pc 0001eb67 /system/lib/libRSCpuRef.so (_ZN7android12renderscript19RsdCpuReferenceImpl16helperThreadProcEPv+138)
  25. 400-400/? A/DEBUG: #04 pc 00041813 /system/lib/libc.so (_ZL15__pthread_startPv+30)
  26. 400-400/? A/DEBUG: #05 pc 00019315 /system/lib/libc.so (__start_thread+6)
  27. com.test.development A/libc: Fatal signal 7 (SIGBUS) in tid 3368 (AsyncTask #4)
  28. ? E/audit: type=1701 msg=audit(1509449660.557:282): auid=4294967295 uid=10133 gid=10133 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=3371 comm=4173796E635461736B202334 reason="memory violation" sig=7
jjhzyzn0

jjhzyzn01#

因此,通过将script.launchoptions传递给convolve3x3.foreach函数,限制了内核操作的交集,问题得到了解决。把它设置在分配范围内就行了。

  1. renderScript = RenderScript.create(ApplicationContext.ApplicationContext())
  2. inputAllocation = Allocation.createFromBitmap(renderScript, sourceBitmap)
  3. val typeInBuilder = Type.Builder(renderScript, Element.F32_4(renderScript)).setX( imageWidth ).setY( imageHeight )
  4. val launchOptions = Script.LaunchOptions()
  5. launchOptions.setX( 0, imageWidth-1 )
  6. launchOptions.setY( 0, imageHeight-1)
  7. launchOptions.setZ( 0, 1 )
  8. // Allocation where to store the sum result (for output purposes)
  9. val coefficientsGx = floatArrayOf(-1f, 0f, 1f, -2f, 0f, 2f, -1f, 0f, 1f)
  10. val coefficientsGy = floatArrayOf(-1f, -2f, -1f, 0f, 0f, 0f, 1f, 2f, 1f)
  11. intermediateAllocation = Allocation.createTyped(renderScript, typeInBuilder.create())
  12. convolve3x3 = ScriptIntrinsicConvolve3x3.create(renderScript, Element.F32_4(renderScript))
  13. convolve3x3.setInput(inputAllocation)
  14. convolve3x3.setCoefficients(coefficientsGx)
  15. convolve3x3.forEach(intermediateAllocation, launchOptions)
展开查看全部

相关问题