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

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
SmartfoxEnjoyer
Posts: 93
Joined: 13 Dec 2023, 20:39

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

Post 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!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

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

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply