Forums

OverviewV-Play 1 SupportFound Bug? (EntityManager) › Re: Found Bug? (EntityManager)

OverviewV-Play 1 SupportFound Bug? (EntityManager) › Re: Found Bug? (EntityManager)
#4144

Elisabeth

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.

main.qml:


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(){
      entityManager.removeAllEntities()

      displayNumCrates()

      scene.spawnCrate()
      //creationTimer.restart()
    }
 
    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);

      displayNumCrates()
  
      deletionTimer.restart();
    }

    function displayNumCrates(){
      var crates = entityManager.getEntityArrayByType("crate")
      if(crates){
        debugText.text = crates.length
      }
    }      

    Component.onCompleted: {
      scene.spawnCrate()
    }
    
    Timer{
      id: creationTimer
      interval: 10
      onTriggered: scene.spawnCrate()
      repeat: false
      running: false
    }

    Timer{
      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
}

Crate.qml:


//![0]
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:


  //scene.spawnCrate()
  creationTimer.restart()

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…

Cheers,
Thomas

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