What is wrong with me?

I was working on my game engine, and it has a “Game” class.


public abstract class Game
{
	
	public Game()
	{
		setup(); //If you call this method here, It will only initialize the variables to their default value
	}
	
	protected void setup()
	{
		
	}

}

and then I have my game’s class, which extends Game.


public class MyGame extends Game
{
	private boolean useShaderPipeline = true;
	
	public MyGame()
	{
		//if you call setup here, and not from the super constructor, everything works ok
	}
	
	protected void setup()
	{
		System.out.println(useShaderPipeline); //Prints false
		useShaderPipeline = true;
		System.out.println(useShaderPipeline); //Prints true
	}
	
	public static void main(String args[])
	{
		new MyGame();
	}

}

Ok, looks good so far. But wait… why does the println’s return 0 and false respectively? It looks like they are at their default values. However if you initialize them inside of a method, they work fine.
My best guesses are:

  1. I fell asleep in the java class where they told me about this. //HIGHLY LIKELY.
  2. There are aliens in my computer.
  3. This is a bug, or a corrupt JVM.

What are your thoughts/suggestions to resolve this?

P.S. If you hit tab while typing up up a post, it focuses you on the search bar. Sort of annoying when you are formatting code :smiley: (Just my $0.02)

With the code you gave me, I get 1 and true on my end. Is there something we’re missing that you’re not providing?

EDIT: Also, this thread seems like it would have been better suited for the “Newbie and Debugging” forum. Not that you’re a newbie! :slight_smile:

Colton

Ok, Just tried my code. That works on my machine too, but the original code does not. ??? I don’t know what I am holding back, but apparently something. Do you want me to pastebin my complete source?

Yes, it’s interesting.

Don’t ask, just do it :slight_smile:

I will post it tomorrow. Off to bed, after I request conversion.

Well this is anti-climax ;D

I think I’ve been affected by this. Well, I can’t reproduce it either though. xD

Once every few months, Eclipse just stops compiling for no reason whatsoever, and you need to close & open the fileyou’re editing, or restart Eclipse. Other cuases can be that there are issues with your build-path, which also stops the compiler (for good reason).

Well, that makes sense. >_>

I have never managed to have eclipse going for a month without having to restart long before then.

However more on topic i have had eclipse stop properly compiling and a simple restart was not enough. I had to “reimport” the project that was affected. ie delete the project then create the project again.

This has happened only twice.

Either way when i am a bit stuck i will always put a “is compiling/running this source” check in. Like a time stamp in the logs for example.

Ok, I have done some debugging, and have found the cause of the error. It seems that if you have a protected method in the superclass, and you call it in it’s constructor, it seems to just skip initializing the variables. However, if you call it in the subclass, it works great. I updated the code and it produces the error after a restart, and even after putting it in a new file. Also, I checked my build path, everything looks good, and it compiles fine.

Agree, it happens to me a lot of times actually. Most of the time it was when I was working with some plug-ins; different version control and maven if I remember correctly. I have no idea why :S I tried everything, build, clear and build, editing and resaving file. Nothing would work. I had to restart eclipse.

Always restart Eclipse. Sit down at the desk? Better restart Eclipse. Alt+tab to another window? Better restart Eclipse.

Think like Bear Grylls, except with Restarting Eclipse… Not what he is known for. Ahem.

Anyway, I’ve gotten to the point where I have to do it every few hours because it stops recognizing imports and marks everything with errors. Or it stops prompting auto-commits. All sorts of fun.

I restarted! And… it still doesn’t work properly. :smiley:

Are all of you working under Linux / Mac OS X?
I’m on win 7 (64bit and 32bit) and NEVER had to restart Eclipse. EVER in over 3 years :slight_smile:

Eclipse works like a like a rainbow unicorn for me. :3

Try rebooting your PC.

Nope, Win7 64! And Eclipse crashes on me about once a day or so! Though, it could be that my AV’s a bit bitchy about things…

Oh! Ah… Should I tell you what your problem is? Because I think I know it. >.>

It’s an inheritance issue. The code that you have up there? Try changing…


protected void setup()
   {
      
   }
to
protected abstract void setup();

Then say whether it works right. :3 If it does, I can explain why! :3

I am working on Mac OS X Lion, and I don’t have to restart too often. (1-2 months in between restarts).

Rebooted, same problem. Also, it appears that the problem occurs system-wide, as my older eclipse(Indigo, kept it just in case in the upgrade to Juno screwed things up) has the same issue.

No, it doesn’t. :frowning: Darn…I was hoping I fell asleep in Java 4 Newbs 101.:wink: That would make everything a lot easier…

Eclipse works like a charm for me. Never any problems :slight_smile: