Author Topic: Clearing all objects upon config change  (Read 318 times)

Offline deqleos

  • byte
  • *
  • Posts: 8
    • View Profile
Clearing all objects upon config change
« on: April 05, 2018, 04:18:13 pm »
Hi,

I'm currently creating an app where a high number of objects are created and removed during the usage.
Now I want to make sure that config changes don't create weird scenarios.
The objects that I create are dependant on the lifetime of a real world object. When the real world object isn't present anymore, the on screen object also has to be removed.
Now this works perfectly fine during the usage of the app. However, when the real world object is present and a config change occurs, the objects stay on the screen and don't get deleted. The problem lays in that the world gets deleted before the app has the chance to remove the objects.
The error i get is: 
ERROR: Can't remove object #1, because it doesn't belong to this World!

TLDR: How can I delete individual objects independent of the world they are in, instead of having to call world.removeObject();

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Clearing all objects upon config change
« Reply #1 on: April 05, 2018, 06:51:53 pm »
I'm not sure, if I understand the problem. If an object belongs to a world, it will be rendered if that world is. If not...then not. Where do you want to remove the object from if not the world? If the exception bothers you and you feel that it's save what you are doing, then just catch and ignore it. However, that might just be a symptom of the actual problem...that I somehow don't get...!?

Offline deqleos

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Clearing all objects upon config change
« Reply #2 on: April 06, 2018, 03:10:54 pm »
I guess the issue is that onSurfaceCreated gets called and a new world gets initialised.
The 3D objects stay in memory for some reason and then I'm trying to delete them from the new world, which obviously won't work.
So the reason I asked for a way to delete individual objects is that I lose reference to the original world.

Anyways, the issue is pretty insignificant for now and is probably very specific to my situation. Thanks though

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Clearing all objects upon config change
« Reply #3 on: April 09, 2018, 07:01:31 am »
Maybe just reuse the world instance? At least that's what I'm doing.

Offline deqleos

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Clearing all objects upon config change
« Reply #4 on: April 12, 2018, 11:40:56 am »
Yeah, that's what I do now as well.