Page 1 of 1

destroy() gets called after init() after extension reload?

Posted: 12 Jan 2024, 22:46
by SmartfoxEnjoyer
Everytime I reload an extension the terminal traces my extension starting up and then immediately after traces the destroy() function being called.

The extension isnt actually being destroyed though, which makes me think the terminal/log is not accurate as it should print the destroy trace first and only afterwards the init traces...

Heres my code as an example:

Code: Select all


   @Override
   public void init() {
      API = getApi();

      trace("ZoneExtension -- started");
      
      _signUp = new SignUp();
      _signUp.Init();
      addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, _signUp.SUAC);
      trace("SignUp Assistant -- started");

      _login = new Login();
      _login.Init(this);
      trace("Login Assistant -- started");

      addEventHandler(SFSEventType.USER_JOIN_ZONE, JoinZoneEventHandler.class);
      addEventHandler(SFSEventType.USER_DISCONNECT, UserDisconnectHandler.class);
      addEventHandler(SFSEventType.USER_LEAVE_ROOM, UserLeaveHandler.class);
      addEventHandler(SFSEventType.USER_LOGOUT, UserLogoutHandler.class);

      addRequestHandler("Characters", RequestCharactersHandler.class);
      addRequestHandler("CreateCharacter", RequestCreateNewCharacterHandler.class);
      addRequestHandler("SelectCharacter", RequestSelectCharacterHandler.class);
      addRequestHandler("DeleteCharacter", RequestDeleteCharacterHandler.class);
      addRequestHandler("JoinServer", RequestJoinServerHandler.class);
      addRequestHandler("MigrateServer", RequestMigrateServerHandler.class);

   }

   @Override
   public void destroy() {
      super.destroy();
      _login.LAC.destroy();
      trace("ZoneExtension -- stopped");
      }
      


And the terminal traces :

Code: Select all


22:32:27,114 INFO  [Thread-3] managers.SFSExtensionManager     - Reloading extension: { Ext: ZoneExtension, Type: JAVA, Lev: ZONE, { Zone: ASOZone0 }, {} }
22:32:27,160 INFO  [Thread-3] Extensions     - {ZoneExtension}: ZoneExtension -- started
22:32:27,163 INFO  [Thread-3] Extensions     - {ZoneExtension}: SignUp Assistant -- started
22:32:27,164 INFO  [Thread-3] Extensions     - {ZoneExtension}: Login Assistant -- started
22:32:27,169 INFO  [Thread-3] Extensions     - {ZoneExtension}: ZoneExtension -- stopped                // weird print? shouldnt this be at the top?


It doesnt really cause any problems, but this behaviour is unexpected I think? Any chance it can be fixed somehow?


Cheers!

Re: destroy() gets called after init() after extension reload?

Posted: 13 Jan 2024, 12:39
by Lapo
Everytime I reload an extension the terminal traces my extension starting up and then immediately after traces the destroy() function being called.

The destroy() invocation you see is not from the new Extension that was just started, but rather from the old instance, which is getting unloaded.
SmartFoxServer first attempts to instantiate and init the new Extension: if the operation is successful it calls destroy() on the old instance, otherwise it will throw an error and continue using the previous Extension.

Cheers