Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2]

Author Topic: General Debugging Crash Course  (Read 13217 times)

Trylobot

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1170
    • View Profile
    • Github profile
Re: General Debugging Crash Course
« Reply #15 on: August 26, 2012, 08:35:10 PM »

@Griffin: Please make that post your last one in this thread with regards to Vim. This is meant to be more general than what editors to use.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: General Debugging Crash Course
« Reply #16 on: September 03, 2012, 02:03:24 AM »

Eclipse with the classpath properly configured.
I personally wouldn't consider modding without it; code auto-complete is invaluable, and makes syntax errors of any kind impossible.

I'll write a tutorial at some point.

Might also be possible to attach a debugger to the running VM; can't get any better debugging than an actual debugger.
Though I have not had need to try this yet myself; it might be quite complicated.
Logged

StickyNavels

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: General Debugging Crash Course
« Reply #17 on: March 05, 2013, 05:05:27 AM »

Quote
I mostly own MS Office because I was required to have a copy for college and it only cost me $15. Even though it sucks on a Mac, I still use it because it's there. I may grab LibreOffice (poor OpenOffice got mangled during the hostile takeover), but I don't want to use up any more of my shrinking hard drive for it. (I really need to grab some external storage...)
Well, aren't you lucky then! There's a portable version of LibreOffice that you can run off of a USB memory. An office suite on the go - it's really quite nice.
Logged

RawCode

  • Admiral
  • *****
  • Posts: 511
    • View Profile
Re: General Debugging Crash Course
« Reply #18 on: March 09, 2013, 08:45:54 PM »

The real crash debugging course:
The real crash evoiding cource:

Add to import section:
Code
import org.apache.log4j.Logger;

Add to class fields section:
Code
	public Logger log = Logger.getLogger(this.getClass());

for static use (a bit more recomended but you wont have chance to get class instance, instance usefull when you have multiple):

Code
public static Logger log = Logger.getLogger(classname.class);

All exception have specific source (game core), all errors generated are RuntimeExceptions, in most cases it's moment of object creation, there is sample of code that allow you to evoid exception due invalid hullid string:
   
Code
			private static FleetMemberAPI _secure;
public boolean secure_createFleetMember(String s) {
String r = "";
try {
// dont call core methods directly, you will aggro devs
// call API instead...
[s]//_secure = new FleetMember(0, s, FleetMemberType.SHIP);[/s]
_secure = Global.getFactory().createFleetMember(FleetMemberType.SHIP,s);
} catch (Exception e) {
log.info(s + " is invalid variant");
r = r + "INVALID VARIANT DETECTED: " + s + "\n\t\t";
return false;
}
return true;
}
If code return true its safe to use current FleetMemberAPI _secure variable to fleet compilation, if not - you shoud cancel your actions, error will be logged into starfarer.log, you will easy find it by name of class that generated error.

Same code can be used to test anything, it resource heavy but ensure smooth gameplay.
Just surround problematic locations with try+catch and add some logic to rest of code.

Logic can be hard to implement in some locations, for this case you shoud use special "null" objects of every type:

If hull not found - we create hull "debug_hull" and proceed normal operations;
If fleet not found - we create fleet "debug_fleet" and proceed normal operations;

Also strongly adviced to place lots of:
log.info("USER ACTIONS WAS" + S);
everywhere in code, this will help a lot in case of unexpected crush

This code can be used to display stacktrace ingame in case of expected error:
Code
     		StackTraceElement[] stack = e.getStackTrace();
String exception = "";
for (StackTraceElement s : stack) {
exception = exception + s.toString() + "\n\t\t";
}
log.info(exception);
Logged
Pages: 1 [2]