Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Hot Code Replace problem.  (Read 667 times)
0 Members and 1 Guest are viewing this topic.
Offline synok

Senior Newbie


Medals: 1



« Posted 2013-10-14 11:25:34 »

Hello,

Up until I reformatted my computer and reinstalled Windows 8 on it, I have not been able to get Hotswapping working again. It worked fine before, but now it wont react at all. I am running a small segment of code to try it out;

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class GameComponent {
   
   public static void main(String[] args) {
      GameComponent gc = new GameComponent();
      gc.run();
   }

   public void run(){
      int x = 0;
      boolean running = true;
      while(running)
      {
         System.out.println("X = " + x);
         x = 2;
      }
   }
}


With this I should be able to run it in Debug mode and change the X value to print something else, but it does not seem to work. All my settings in Eclipse is default and I am having "Build Automatically" checked. Is there any more suggestions? Someone on LWJGL IRC said something about the build path but I think everything is OK there too.

Thanks,
Offline Troncoso

JGO Coder


Medals: 20



« Reply #1 - Posted 2013-10-14 11:32:19 »

That worked for me. How are you trying to change it? Are you setting a break point?
Offline synok

Senior Newbie


Medals: 1



« Reply #2 - Posted 2013-10-14 12:08:45 »

That worked for me. How are you trying to change it? Are you setting a break point?

I am not setting any breakpoints, just running it in Debug mode and it starts printing the value of X, I am trying to change the value and saving but it does not change.

You may check if there are any problems with automatic building. First look at the project icon in the project explorer view, if there is a exclamation mark at it then it possibly cannot build automatically.  You would have to open the "problems" view in "Window -> Show view -> problems". A window will popup. I've run to such problems several times and its pretty annoying.

I checked the "Problems" window, but there is nothing there it seems. And I do not think I have some exclamation mark if the "Package Explorer" is what you mean.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 803
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2013-10-14 12:24:34 »

By default, Eclipse changes entire methods, not individual lines of code. For a replaced method to  become effective, it has to be called. This means that when multiple threads are accessing this method, each may be executing its own version of the method.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline synok

Senior Newbie


Medals: 1



« Reply #4 - Posted 2013-10-14 12:30:04 »

By default, Eclipse changes entire methods, not individual lines of code. For a replaced method to  become effective, is has to be called. This means that when multiple threads are accessing this method, each may be executing its own version of the method.

Is there a way to solve it?

Anyhow, figured out something interesting. I set a breakpoint on "System.out.println" and it stopped running the code when it hit it, so I ran it a few times getting the same value of X printed out. I changed the value and then continued to run it, breaking a few times at the breakpoint. This worked though, the X value was showing the changed value.

So I guess it only works if I hit the breakpoints though. Weird, but a clue.
Offline Troncoso

JGO Coder


Medals: 20



« Reply #5 - Posted 2013-10-14 12:34:57 »

You don't necessarily need breakpoints. I've tested it, and while your code doesn't work, this does (without breakpoints):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Test {
    private static int ctr = 0;
    public static void main(String[] args) {
        while (true) {
            method();
        }
    }

    private static void method() {
        System.out.println(ctr);
    }
}


You can change "ctr" to anything you want, and the change will reflect in the output. Adding breakpoints allows the JVM to "refresh" the stack frame. Here's a quote that I think explains why your specific code doesn't work:

Quote
There are some cases where the feature will not work. E.g. if you make changes to your main method's a4 variable, the JVM will not be able to remove all stack frames running old code from the call stack. The debugger data will be lost.

Link
Offline synok

Senior Newbie


Medals: 1



« Reply #6 - Posted 2013-10-14 12:37:22 »

Your code works!

So it was my code all along. Thanks for your help, now I know that my settings in Eclipse are just fine.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!