Forums

OverviewFelgo 2 Support (Qt 5) › Felgo App crashed on NavigationStack back button (PhysicsWorld + BoxCollider)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22678

    Sylvia Winkler

    Hi,

    my Felgo App crashes every time I use PhysicsWorld+BoxCollider and then navigate back from the NavigationStack. This behaviour only appears when I use those two components combined (PhysicsWorld and BoxCollider). My guess is that the deconstruction of entities is causing troubles (see StackTrace below). It crashes in the LiveDemo on my computer and on my phone (iOS) as well.

    This is a minimal version of the code that crashes:

    import Felgo 3.0
    import QtQuick 2.0
    
    App {
    
        NavigationStack {
            Page {
                id: main
    
                SimpleButton {
                    text: "next scene"
                    onClicked: main.navigationStack.push(component)
                }
            }
        }
    
        Component {
            id: component
    
            Page {
                GameWindowItem {
                    activeScene: subScene
    
                    EntityManager {
                        id: entityManager
                        entityContainer: subScene
                    }
    
                    Scene {
                        id: subScene
    
                        PhysicsWorld {
                            gravity: Qt.point(0, 25)
                        }
    
                        EntityBase {
                            id: player
                            entityType: "player"
                            width: 25
                            height: 25
    
                            Rectangle {
                                anchors.fill: parent
                                color: "blue"
                            }
    
                            BoxCollider {
                                id: playerCollider
                                anchors.fill: parent
                            }
                        }
                    }
                }
            }
        }
    }
    

    An excerpt from the crash report:
    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0 net.vplay.apps.QMLLive 0x000000010b4cbc4a Box2DBody::~Box2DBody() + 42
    1 net.vplay.apps.QMLLive 0x000000010b4c533f QQmlPrivate::QQmlElement<Box2DBody>::~QQmlElement() + 47
    2 org.qt-project.QtCore 0x000000010dd980e0 QObjectPrivate::deleteChildren() + 224
    3 org.qt-project.QtCore 0x000000010dd97ec4 QObject::~QObject() + 1700
    4 org.qt-project.QtQuick 0x000000010bf32647 QQuickItem::~QQuickItem() + 871

    I am using MacOS, QtCreator 4.10.2, Felgo 3.3.0.

    What can I do to avoid this problem?

    Thanks for your help!

    Sylvia

    #22682

    Alex
    Felgo Team

    Hi Sylvia,

    we recommend not to destroy the PhysicsWorld, as this can cause unexpected behaviour, e.g. the crash you experience. Our usual recommendation is to have one instance of your PhysicsWorld in your root component, and re-parent it to your desired component when required. Here is a quick example of how this could look like:

    import Felgo 3.0
    import QtQuick 2.0
    
    App {
    
        // those aliases as child of the root item make the id's available globally
        property alias physicsContainer: physicsContainer
        property alias physicsWorld: physicsWorld
        
        Item {
            id: physicsContainer
            anchors.fill: parent
    
            PhysicsWorld {
                id: physicsWorld
                gravity: Qt.point(0, 25)
            }
        }
    
        NavigationStack {
            Page {
                id: main
    
                SimpleButton {
                    text: "next scene"
                    onClicked: main.navigationStack.push(component)
                }
            }
        }
    
        Component {
            id: component
    
            Page {
                // depending on your app, there might be better spots where to do the re-parenting and start/stop your game
                onPushed: {
                    physicsWorld.parent = subScene
                }
                onPopped: {
                    physicsWorld.parent = physicsContainer
                }
                GameWindowItem {
                    activeScene: subScene
    
                    EntityManager {
                        id: entityManager
                        entityContainer: subScene
                    }
    
                    Scene {
                        id: subScene
    
                        EntityBase {
                            id: player
                            entityType: "player"
                            width: 25
                            height: 25
    
                            Rectangle {
                                anchors.fill: parent
                                color: "blue"
                            }
    
                            BoxCollider {
                                id: playerCollider
                                anchors.fill: parent
                            }
                        }
                    }
                }
            }
        }
    }
    

    Let me know if such an approach works for you or if there are any more questions.

    Cheers,
    Alex

    #22683

    Sylvia Winkler

    Hi Alex,

    thanks for the fast and helpful answer! That totally solved my issue.

    Have a great week,

    Sylvia

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support