Reply
Thread Tools Display Modes
Unread 10-26-14, 05:52 PM   #1
Nimhfree
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 154
PLAYER_LOGIN issue?

Hi. There seems to be a situation where a slash command is being registered in ADDON_LOADED, and a frame upon which it relies is not being registered until PLAYER_LOGIN. So, in cases I cannot reproduce, someone is able to issue the slash command before the frame is created and crash.

Are there cases when ADDON_LOADED is called but PLAYER_LOGIN is not? I know PLAYER_ALIVE is not called upon UI reload (or at least this was the case prior to WoD).

I am thinking I will just move the frame creation into ADDON_LOADED, but would like to know whether I can reproduce this before I do, just in case other things should be moved as well.
Nimhfree is offline   Reply With Quote
Unread 10-26-14, 06:46 PM   #2
Lombra
A Frostmaul Preserver
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 250
PLAYER_LOGIN will always happen on UI load. (actual login and UI reload) If your addon is loaded on demand it might be loaded (as in ADDON_LOADED) when PLAYER_LOGIN has already happened, otherwise I'm pretty sure all non LoD addons will load before that.

Personally though, I always create frames in the main chunk, unless their creation is based on some saved variables.
__________________
Grab your sword and fight the Horde!
Lombra is offline   Reply With Quote
Unread 10-26-14, 06:54 PM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,751
As each addon loads, WoW reads its TOC file, then loads all the files listed in its TOC in order (and any files listed in them, in case of XML files, also all in order), then loads its saved variables file(s) if it has any, and then fires an ADDON_LOADED event with the addon's folder name as the first and only argument.

All addons that are not configured to load on demand are loaded before PLAYER_LOGIN fires. Unless your addon is LOD or has a LoadManager, its ADDON_LOADED event will always fire before PLAYER_LOGIN.

You should not use PLAYER_ALIVE or VARIABLES_LOADED or any other events to initialize your addon. If you are sure your addon is not load-on-demand and does not have a LoadManager, you can just do everything in PLAYER_LOGIN, since your ADDON_LOADED event will always fire before PLAYER_LOGIN.

If you are not sure, or you are still having problems, here is a good fool-proof loading process that will work regardless of whether your addon is LOD or has a LoadManager, on both a /reload and on a fresh login:

Code:
local ADDON_NAME = ...

local f = CreateFrame("Frame", "MyAddonFrame")
f:SetScript("OnEvent", function(self, event, ...) return self[event](self, event, ...) end)
-- ^ Generic event dispatcher.

f:RegisterEvent("ADDON_LOADED")

function f:ADDON_LOADED(addon)
     if addon ~= ADDON_NAME then
          -- Some other addon was loaded, but we don't care.
          return
     end

     -- Initialize your saved variables here.
     -- If anything was previously saved, it's now loaded.

     -- We don't care about any further addon loading events, so stop listening.
     self:UnregisterEvent("ADDON_LOADED")
     self.ADDON_LOADED = nil

     if IsLoggedIn() then
          -- We're already done logging in, probably using a LoadManager.
          -- Just call the login event handler manually:
          self:PLAYER_LOGIN()
     else
          -- We're not logged in yet, so wait for that to happen:
          self:RegisterEvent("PLAYER_LOGIN")
     end
end

function f:PLAYER_LOGIN()
     -- Now you can create/setup frames, register other events, do all the things!

     -- The login event can't fire twice in a session, so send this handler off to the garbage collector:
     self:UnregisterEvent("PLAYER_LOGIN")
     self.PLAYER_LOGIN = nil
end
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-07-14, 08:08 PM   #4
MoonWitch
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 437
Originally Posted by Phanx View Post
As each addon loads, WoW reads its TOC file, then loads all the files listed in its TOC in order (and any files listed in them, in case of XML files, also all in order), then loads its saved variables file(s) if it has any, and then fires an ADDON_LOADED event with the addon's folder name as the first and only argument.

A..snip..
Niice - This should be stacked : )
__________________
MoonWitch is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » PLAYER_LOGIN issue?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off