Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved cloudAnchorNode crash issue in ar-cloude-anchor sample project #545

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.sceneview.sample.arcloudanchor
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.EditText
Expand Down Expand Up @@ -50,7 +51,9 @@ class MainFragment : Fragment(R.layout.fragment_main) {
hostButton.isVisible = true
resolveButton.isVisible = true
actionButton.isVisible = false
cloudAnchorNode.isVisible = false
if (::cloudAnchorNode.isInitialized) {
cloudAnchorNode.isVisible = false
}
}

Mode.HOST -> {
Expand All @@ -62,7 +65,10 @@ class MainFragment : Fragment(R.layout.fragment_main) {
isVisible = true
isEnabled = true
}
cloudAnchorNode.isVisible = true
if (::cloudAnchorNode.isInitialized) {
Log.e(TAG, "CloudAnchorNode resolved")
cloudAnchorNode.isVisible = true
}
}

Mode.RESOLVE -> {
Expand Down Expand Up @@ -94,12 +100,14 @@ class MainFragment : Fragment(R.layout.fragment_main) {
loadingView.isGone = !value
}

var cloudAnchorId by requireContext().getSharedPreferences("preferences", Context.MODE_PRIVATE)
.string(defaultValue = null)
private var cloudAnchorId: String? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

cloudAnchorId = requireContext().getSharedPreferences("preferences", Context.MODE_PRIVATE)
.string().toString()

val topGuideline = view.findViewById<Guideline>(R.id.topGuideline)
topGuideline.doOnApplyWindowInsets { systemBarsInsets ->
// Add the action bar margin
Expand Down Expand Up @@ -165,7 +173,8 @@ class MainFragment : Fragment(R.layout.fragment_main) {
return
}
val anchor = cursorNode.createAnchor() ?: return

session.hostCloudAnchorAsync(anchor, 20,null)
cloudAnchorNode = CloudAnchorNode(sceneView.engine, anchor, cloudAnchorId)
sceneView.addChildNode(CloudAnchorNode(sceneView.engine, anchor).apply {
host(session) { cloudAnchorId, state ->
mode = if (state == CloudAnchorState.SUCCESS && cloudAnchorId != null) {
Expand Down