Thread Tools Display Modes
06-17-05, 02:40 AM   #1
Sathanas
A Deviate Faerie Dragon
 
Sathanas's Avatar
AddOn Author - Click to view addons
Join Date: May 2005
Posts: 15
Tracking down a math crash

Ive been putting off working on what i consider my greatest work with the UI stuff ( http://www.wowinterface.com/download...php?s=&id=3968 ) because it has a bad tendancy to crash the game with c_math.cpp errors.

I understand that this is most often caused by divide by zero, but ive peppered so many "if (thisthing == 0) then thisthing = 1; end" in there that its overloaded.

I cant even pinpoint whats happening that causes these crashes. It will happen at completely random times when i have nothing targetted (which makes no sense, considering my mod is a target panel replacement and shouldnt be doing the main update function at all with no target), but i can confirm that it is my mod causing it. When i disable SathPanel, the crashes cease.

Anyone have any reccomendations on good techniques to narrow down what could be causing this? Im not even sure what all besides dividing by zero will cause math crashes at all
__________________
--Sathanas
  Reply With Quote
06-17-05, 10:38 AM   #2
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
One thing I have had to do, is to comment out huge blocks of code that would be described as a 'fuctional portion' start off with very little left un commented and slowly open up functionality. After you start to get the bug then work that part that you just opened up till you have no more bugs. repeat until everything is uncommented
  Reply With Quote
06-17-05, 10:51 AM   #3
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
you can also add chat message calls to relevant portions of code that you think might be causing a problem. Use it as debug code, and comment it out when you are done with it. As an example, I stuck in some basic chatframe outputs to your SathPanel_UpdateDPS function, and included it below. Try this and see if it helps:

Code:
function SathPanel_UpdateDPS()
	local TimeElapsed = (GetTime() - FightStartTime) + 1;
	ChatFrame1:AddMessage("SathPanel_UpdateDPS() Checkpoint: TimeElapsed = "..TimeElapsed, 1, 1, 1);	
	if (PlayerDPSConfig == 1) then
		if (PlayerDamage < 1) then		  -- Begone stupid divide by zero crashes
			PlayerDamage = 1;
		end
		local PlayerDPS = PlayerDamage / TimeElapsed;
	    ChatFrame1:AddMessage("SathPanel_UpdateDPS() Checkpoint: PlayerDPS = "..PlayerDPS, 1, 1, 1);   
		PlayerDPS = PlayerDPS + LastPlayerDamage;
	    ChatFrame1:AddMessage("SathPanel_UpdateDPS() Checkpoint: PlayerDPS = "..PlayerDPS, 1, 1, 1);   
		PlayerDPS = PlayerDPS / 2;
	    ChatFrame1:AddMessage("SathPanel_UpdateDPS() Checkpoint: PlayerDPS = "..PlayerDPS, 1, 1, 1);   
		SathPanel_PlayerDPS:SetText("DPS: "..math.floor(PlayerDPS+0.05));
		LastPlayerDamage = PlayerDPS;
	end
	if (TargetDPSConfig == 1) then
		if (EnemyDamage < 1) then
			EnemyDamage = 1;
		end
		local TargetDPS = EnemyDamage / TimeElapsed;
		TargetDPS = TargetDPS + LastEnemyDamage;
		TargetDPS = TargetDPS / 2;
		SathPanel_TargetDPS:SetText("DPS: "..math.floor(TargetDPS+0.05));
		LastEnemyDamage = TargetDPS;
	end
end
  Reply With Quote
06-17-05, 03:42 PM   #4
Sathanas
A Deviate Faerie Dragon
 
Sathanas's Avatar
AddOn Author - Click to view addons
Join Date: May 2005
Posts: 15
Thanks for the replies

It really is a huge headache to try to track down, mainly because the crashes were extremely rare to begin with, and with no idea of what section of my mod was causing it there was no way to force the issue to occur in-game to see if any fixes work.

Im actually pretty certain that its not in the DPS system, i added those TargetDPSConfig and PlayerDPSConfig for the sole reason of turning the DPS on and off to see if the crashes occured with DPS off (and they do )

Oh well, ill find it somehow
__________________
--Sathanas
  Reply With Quote
06-17-05, 07:34 PM   #5
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
After looking further into your script, I see the following:

Code:
function SathPanel_ColorG(min, max)
	local colorg = min / max;  
	return colorg;	  
end

function SathPanel_ColorR(min, max)
	local colorr = min / max;
	colorr = 1 - colorr;
	return colorr;
end

function PlayerBarThing(min, max)
	local value = min / max;
	value = value * 100;
	value = value / 100;
	value = value * 119;
	return math.floor(value+0.5);
end

function Percentize(min, max)
	local value = min / max;
	value = value * 100;
	return value;
end
By itself those are not a problem, however if max is every defined as zero, you will get an error. You might want to put an error check there and see if it clears your problems up. Possible reasons for this is that the event in your OnEvent function is independant of the VARIABLES_LOADED event, which means it may get called before all variables are loaded, which means some of the UNIT_HEALTH data could get returned as 0 since it is not yet initialized.

If a simple error check doesn't work, think about having the OnEvent function toggle a setting to true from false once variables are loaded. Then tell the other events in taht same function to only actually fire if that flagged variable has been toggled to true...

If that doesn't help I will try playing with the addon too installed in my client and see if I can locate the specific location of the error. I am trying to avoid doing that simply because its your mod. In my experience I learn more by fixing it myself, which may be the case for you too, so I don't want to take that away from you

on an unrelated note, min and max are part of the math library (math.min, math.max) and show as reserved by my syntax highlighter as well as a few others. I don't believe it will cause a problem by using them as identifiers, but I prefer to be more safe than sorry. You might consider renaming them a little just to avoid any potential problems...

Last edited by Beladona : 06-17-05 at 07:50 PM.
  Reply With Quote
06-17-05, 11:33 PM   #6
Sathanas
A Deviate Faerie Dragon
 
Sathanas's Avatar
AddOn Author - Click to view addons
Join Date: May 2005
Posts: 15
*smacks forehead with hand*

Sometimes it just takes someone else looking it over to see the obvious.

SathPanel is about the largest thing ive ever written. Sometimes i get lost in all that code. Thanks!

One thing i meant to ask if anyone had any ideas for, was my health bar color fading. It works well enough as it is fading from green to red as the value decreases, but it looks really dull and dark and cruddy in the middle. Am i missing some easy way of brightening up the colors as the values for R and G are both at their midpoints?
__________________
--Sathanas
  Reply With Quote
06-18-05, 10:47 AM   #7
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
try forcing red to never reach a full color value of 1. This will make it so that when green is at half, red will be less than half. Your ugly color is occuring because green and red are both reaching 0.5 which turns out as a very muddy orange/brown...

Code:
-- first get your health percentage, basically current health / max health
-- the percentage should return as a decimal value between 1.0 and 0.0
-- once you have that percentage, call the next function with the percentage as the argument
SathPanel_GetColorFade(percent)
	local red = (1-percent) * 100;
	local color = {r = red/125; g = percent; b = 0;};
	return color;
end
Basically the highest red will ever reach is 0.8, which is a bright enough red for when you reach little to no health. Green will be offset from red, effectively eliminating that muddy color you saw...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Tracking down a math crash

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