[SOLVED] Problem with resetting filter after stopping EntityContainer


#1

After stopping EntityContainer, if I reset filter (before staring it again) I will get this exception:

19:07:23,700 ERROR [KernelAdapter] Unhandled error, endpoint:NioEndpoint[1, java.nio.channels.SocketChannel[connected local=/127.0.0.1:4273 remote=/127.0.0.1:35038]], context:ResetEntitySetFilterMessage[9, FieldFilter[private com.simsilica.es.EntityId com.otm.moona.common.core.component.SpawnPosition.sceneId == EntityId[1]]]
java.lang.RuntimeException: Error executing:public void com.simsilica.es.server.HostedEntityData.resetEntitySetFilter(com.jme3.network.HostedConnection,com.simsilica.es.net.ResetEntitySetFilterMessage)
	at com.simsilica.es.net.AbstractMessageDelegator.messageReceived(AbstractMessageDelegator.java:238) ~[zay-es-net-master-SNAPSHOT.jar:?]
	at com.simsilica.es.net.AbstractMessageDelegator.messageReceived(AbstractMessageDelegator.java:59) ~[zay-es-net-master-SNAPSHOT.jar:?]
	at com.jme3.network.base.MessageListenerRegistry.messageReceived(MessageListenerRegistry.java:81) ~[jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.DefaultServer.dispatch(DefaultServer.java:341) ~[jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.DefaultServer$Redispatch.messageReceived(DefaultServer.java:674) ~[jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.DefaultServer$Redispatch.messageReceived(DefaultServer.java:669) ~[jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.KernelAdapter.dispatch(KernelAdapter.java:187) [jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.KernelAdapter.createAndDispatch(KernelAdapter.java:241) [jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
	at com.jme3.network.base.KernelAdapter.run(KernelAdapter.java:284) [jme3-networking-3.3.0-SNAPSHOT.jar:3.3-6611]
Caused by: java.lang.NullPointerException
	at com.simsilica.es.server.HostedEntityData.resetEntitySetFilter(HostedEntityData.java:318) ~[zay-es-net-master-SNAPSHOT.jar:?]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
	at com.simsilica.es.net.AbstractMessageDelegator.messageReceived(AbstractMessageDelegator.java:231) ~[zay-es-net-master-SNAPSHOT.jar:?]
	... 8 more

my code :

 @Override
    protected void onEnable() {
        if (!selectionScene.equals(EntityId.NULL_ID)) {
            terrainEntity = ed.watchEntity(selectionScene, TerrainProperty.class, Level.class);
            terrainEntity.applyChanges();

            terrainNode = new Node("terrain");
            landscapeNode = loadLandscape();

            initMaterials();
     
            terrainBlocks.setFilter(Filters.fieldEquals(SpawnPosition.class, "sceneId", selectionScene));
            bridgeBlocks.setFilter(Filters.fieldEquals(SpawnPosition.class, "sceneId", selectionScene));
            
            terrainBlocks.start();
            bridgeBlocks.start();

            terrainNode.setUserData(UD_ENTITY_ID, selectionScene.getId());
            Node rootNode = ((SimpleApplication) getApplication()).getRootNode();
            rootNode.attachChild(terrainNode);
            rootNode.attachChild(landscapeNode);
        }

        EventBus.addListener(this, SceneChangeEvent.sceneChanged);
    }

    @Override
    protected void onDisable() {
        if (!selectionScene.equals(EntityId.NULL_ID)) {
            terrainNode.removeFromParent();
            terrainNode.detachAllChildren();

            landscapeNode.removeFromParent();
            landscapeNode.detachAllChildren();

            terrainBlocks.stop();
            bridgeBlocks.stop();
            terrainEntity.release();
        }

        EventBus.removeListener(this, SceneChangeEvent.sceneChanged);
    }

   

    private void onSceneChanged(SceneChangeEvent event) {
            onDisable();
            selectionScene = event.getSceneId();
            onEnable();           
    }

if I move this part

terrainBlocks.setFilter(Filters.fieldEquals(SpawnPosition.class, "sceneId", selectionScene));
bridgeBlocks.setFilter(Filters.fieldEquals(SpawnPosition.class, "sceneId", selectionScene));

after this :

terrainBlocks.start();
bridgeBlocks.start();

then it will work fine.

Not sure but I guess setting this.entities = null; after calling this.entities.release(); in stop() method may fix it.

this will make sure below check not pass:


#2

Yes, I think you’re right about the fix. Nice sleuthing.


#3

This PR should fix it


#4

Already applied… though I forgot to update the release notes.

Edit: done


#5

Thanks.