Jump to content

WorldLogic shutdown is not always called on CIGI reset?


photo

Recommended Posts

Hi, a WorldLogic is supposed to call its init() when a world is loaded and its shutdown() when the world is unloaded. I use extensively this in our code.

But I stumble on strange behavior: with the same code, multiple CIGI reset can work perfectly, triggering a succession of init/shutdown in my WorldLogic instances. And randomly, it can fail to call the shutdown(). As I now use this to clear some pointers, I get a crash in update() because the pointer is dangling.

Q: can you confirm my understanding of init/shutdown is correct with regard to CIGI reset.

Q: in 2.16.1, is there a way or reason that could prevent the shutdown to be called?

Q: Is there a possibility that update is called while shutdown() is still pending (ie it is about to be called, but the crash happens because an update() is spuriously called before, but all objects in the world have already been destroyed)

Link to comment

 I checked this case, world shutdown is always called. 

but, I seem to have found what can cause crashes in your application:

when `ig_status = operate` is arrived we clear all objects and call world_reload. but engine does reload not immediately, but after two frames (it could be my usage error or the behavior of the engine suddenly changed - I'm trying to figure it out)

> World update
> World post update
> Manager update
> DESTROY ALL ENTITY AND VIEWS << arrive ig_node standby
> call world_reload
Unigine~# world_reload
> World update << still update
> World post update << still update
> Manager update << still update
> World update << still update
> World post update << still update
> ===== World SHUTDOWN ===== 
World loading "project.world" (Time: 30.3ms, Memory: 78.0KB)
> ===== World INIT ===== 
> Manager update
> World update
> World post update

as a temporary solution, I can suggest using a workaround like this:

cigi = IG::CIGI::Connector::get();
cigi->addOnReceivePacketCallback(IG::CIGI::CIGI_OPCODE_IG_CONTROL,
	MakeCallback(
		[](Unigine::Plugins::IG::CIGI::CigiHostPacket *host_packet)
		{
			IG::CIGI::CigiIGControl *packet = dynamic_cast<IG::CIGI::CigiIGControl *>(host_packet);
			if (packet->getIGMode() == IG::CIGI::CIGI_MODE_STANDBY)
			{
				Log::message("need to clear all references like in WorldLogic::shutdown\n");
			}
		}));

 

Link to comment

Indeed, this is what happens as you described: world destroy -> some update() -> shutdown()

The workaround works, but I found it problematic that there can still be some updates when the world has been destroyed but shutdown is not yet called. I think this should be fixed (ie: don't call update when a shutdown is pending and if init hasn't been called: an update should not be called outside of a init/shutdown fence).

  • Like 1
Link to comment
×
×
  • Create New...