Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 1 Support › Found Bug? (EntityManager)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #4001


    User Schustiii and I have found a problem with the entityManager, which we have already solved now.

    We are creating a lot (~ 64) entities dynamically in the entity Manager. (Everybody knows when the entity Manager creates an Object, an ID is also created.) And there was the problem.

    If we were creating a entity of Jewel3, the id was for example called:

    Some time later when we wanted to create a new Jewel3 entity, there was a Warning that there is already an id …Jewel3.qml_32, so he named it file:///C:/FH/Dropbox/FREIGABE/VPlay-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/qml/entities/Jewel3.qml_32_

    The Next element was named: ….Jewel3.qml_32__ and so on.

    And Here is the Problem: We are storing the IDs in a 2D Array. And at some point of the program comes an error: At the Command where we want to delete an entity which is in our Array (So it must exsist) but the entityManager doesnt know anything about it (aaaannd crash). Weird?

    So we thought, the mistake has to be in our code. We were searching several days, but didn’t find anything.

    But than we found the solution: We created our ids manually. and everything works.

    So the EntityManager has some problems obviously. It seems that he deletes some object manually without any commands. But Why?


    Felgo Team

    Hi Hochi,

    I had a look at the EntityManager (EM) and did write a test for your described behavior. However, everything works as expected and I could not find any problems!?

    Could you post the relevant source code that is not working as expected here please?

    Without specifiying your own entityId, the EM should not post a warning about the id being already defined and not append a “_”.It only does that, if you manually set the same entityId. And if your provided one already exists, it will change the id so it is unique.

    This is the example I used:

          SimpleButton {
            text: "add normal"
            onClicked: {
              var newEntityProperties = {
                x: Math.random()*scene.width,
                y: Math.random()*scene.height,
                rotation: Math.random()*360,
                // NOTE: if an entityId is set explicitly, the entityManager will try to set it to this id
                // however, when the entityId already exists in the entityManager, a "_" will be appended
                // thus always retrieve the entityId after a call to createEntity...()
                entityId: "entityNormal"
              var entityId = entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("EntityNormal.qml"),newEntityProperties);
              console.debug("created entity with id:", entityId)
          SimpleButton {
            text: "remove normal"
            onClicked: {
              // when 3 entities are added, and all of them got set the entityId set to "entityNormal", they are removed correctly here




    Hi everyone,

    maybe i stumbled upon the same / a related problem with the EntityManager as I get a similar Warning when trying to delete a dynamically created entity. The following source creates an entity and removes it after two seconds. Afterwards a fresh entity is created and so on.


    import VPlay 1.0
    import QtQuick 1.1
    import Box2D 1.0 // for accessing the Body.Static type
    GameWindow {
      activeScene: scene
      width: 960
      height: 640
      EntityManager {
        id: entityManager
        entityContainer: scene
      Scene {
        id: scene
        width: 480
        height: 320
        function killCrate(){
        function spawnCrate(){
          var xPos = Math.random() * scene.width
          xPos = Math.max(50, Math.min(scene.width - 50, xPos))
          var yPos = 50
          var props = {
            x: Math.max(50, Math.min(scene.width - 50, Math.random() * scene.width)),
            y: 50,
            width: 30,
            height: 30
          var crate = entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("Crate.qml"), props);
        function displayNumCrates(){
          var crates = entityManager.getEntityArrayByType("crate")
            debugText.text = crates.length
        Component.onCompleted: {
          id: creationTimer
          interval: 10
          onTriggered: scene.spawnCrate()
          repeat: false
          running: false
          id: deletionTimer
          interval: 2000
          onTriggered: scene.killCrate()
          repeat: true
          running: false
        PhysicsWorld {
          id: physicsWorld
          height: parent.height
          updatesPerSecondForPhysics: 60
          velocityIterations: 5
          positionIterations: 5
          gravity.y: -0.81
          running: true
        }// physicsWorld
        Rectangle {
          id: backgroundRectangle
          anchors.fill: parent
          color: "grey"
          z: -10
        Text {
          id: debugText
          anchors.right: parent.right
          anchors.top: parent.top
          width: 50
          height: 10
          color: "red"
      } // scene


    import QtQuick 1.1
    import VPlay 1.0
    import Box2D 1.0 // for accessing the Body.Static type
    EntityBase {
      id: entityBase
      entityType: "crate"
      transformOrigin: Item.TopLeft
      BoxCollider {
        anchors.fill: parent
        bodyType: Body.Dynamic
        Rectangle {
          color: "black"
          anchors.fill: parent

    The disease pattern:
    Every second crate survives removeAllEntities(). In the top right corner the number of managed crates is displayed (always “1” although two crates are temporarily visible).

    The workaround:
    The problem seems to stem from the direct recreation of the entity after removing the previous one. As a workaround, you can try to change the killCrate() function to the following:


    Now the new entity is created after a short pause and everything works as expected.

    I hope the above showcases Hochi’s problem. Anyway the observed behavior is somehow strange…



    Felgo Team

    Hi Thomas,
    thanks a lot for your great test! I was able to reconstruct and fix the issue in the EntityManager thanks to it. As you assumed correctly, the issue only happened if the creation is done right after the removal. The fix will be added in the next update version 1.3.

    In the meantime, please delay the creation slightly or set entityIds that are unique after removal and creation. That might be done for example by adding an own entityCounter int property which does not get decreased when an entity is removed.


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

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded