-
-
Notifications
You must be signed in to change notification settings - Fork 204
Description
Device HUAWEI MARK-LX2J
Android version: 10
reason: destroying material "View" but 3 instances still alive.
Precondition in terminate:221 reason: destroying material "View" but 3 instances still alive. Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15757 (m.sample.app), pid 15757 (m.sample.app) pid: 15757, tid: 15757, name: m.sample.app >>> com.sample.app <<< #01 pc 000000000022ad60 /data/app/com.sample.app-BP84K9eTXciOY_Xj0_eKjA==/base.apk!libfilament-jni.so (offset 0x1f94000) (utils::TPanic<utils::PreconditionPanic>::panic(char const*, char const*, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>)+176) (BuildId: a2fceedcbbf416a5962deb92907cf4c2753db6f4) channel 'd26f058 com.sample.app/com.sample.app.ui.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! Window handle Window{d26f058 u0 com.sample.app/com.sample.appui.MainActivity} has no registered input channel win=Window{d26f058 u0 com.sample.fma/com.sample.app.ui.MainActivity EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true notifyActivityState pkg:com.sample.app/com.sample.app.ui.MainActivity state:20 fg:false mUid:10212
code:
`
@androidentrypoint
class SceneViewFragment : Fragment() {
companion object {
fun newInstance() = SceneViewFragment()
}
private var _binding: FragmentSceneViewBinding? = null
private val binding get() = _binding!!
private val viewModel: SceneViewViewModel by viewModels()
private lateinit var sceneView: SceneView
private lateinit var attachmentManager: ViewAttachmentManager
private lateinit var seatNode: ModelNode
private var isEditMode = false
private val labels = mutableListOf()
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)
// TODO: Use the ViewModel
}
override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View {
_binding = FragmentSceneViewBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val btnBack = binding.btnBack5
val btnEdit = binding.btnEdit
sceneView = binding.sceneView
attachmentManager = ViewAttachmentManager(requireContext(), sceneView)
seatNode = ModelNode( modelInstance = sceneView.modelLoader.createModelInstance(R.raw.car_seat), scaleToUnits = 1.0f )
sceneView.addChildNode(seatNode)
sceneView.onTouchEvent = { motionEvent, hitResult ->
if (motionEvent.action == MotionEvent.ACTION_UP && isEditMode) {
if (hitResult?.node == seatNode) {
addLabelAtPosition(hitResult.worldPosition)
}
}
false
}
btnEdit.setOnClickListener {
isEditMode = !isEditMode
btnEdit.text = getString(if (isEditMode) R.string.save else R.string.edit)
}
btnBack.setOnClickListener {
runExitAnimation(requireView())
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
runExitAnimation(requireView())
}
}
override fun onResume() {
super.onResume()
attachmentManager.onResume()
}
override fun onPause() {
super.onPause()
attachmentManager.onPause()
}
override fun onDestroyView() {
sceneView.destroy()
super.onDestroyView()
_binding = null
}
private fun runExitAnimation(view: View) {
view.pivotX = (view.width / 2f)
view.pivotY = (view.height / 2f)
view.animate().scaleX(0f).scaleY(0f).alpha(0f).setDuration(400) .withEndAction {
findNavController().popBackStack()
}
}
private fun addLabelAtPosition(worldPosition: Position) {
val localPosition = seatNode.getLocalPosition(worldPosition)
val labelNode = ViewNode(
engine = sceneView.engine,
modelLoader = sceneView.modelLoader,
viewAttachmentManager = attachmentManager
).apply {
position = localPosition
loadView(
context = requireContext(),
layoutResId = R.layout.layout_3d_label
) { _, view ->
view.findViewById<TextView>(R.id.tvLabel).text = "New Point"
view.setOnLongClickListener {
if (isEditMode) {
seatNode.removeChildNode(this)
labels.remove(this)
}
true
}
}
}
seatNode.addChildNode(labelNode)
labels.add(labelNode)
}
}
`
My goal is to add a label in the point where I click somewhere on the 3D model.
My current situation right now is this.
As long as I don't add a label and goes back to the previous fragment, crash doesn't happen but when I add a label and goes back to the previous fragment, this crash is happening.
Please help.