Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (563)
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  
  A stupid bug I wrote...  (Read 912 times)
0 Members and 1 Guest are viewing this topic.
Offline theagentd
« Posted 2014-01-27 15:22:36 »

Wrote this code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
         target.set(position).add(direction);
         up.set(0, 1, 0);
         if(direction.x == 0 && direction.y == 0);{
            up.set(0, 0, 1); //Ensure up is not the same direction as "direction"
        }

         System.out.println(up); //Bug: up is always (0, 0, 1).

         viewMatrix.setToLookAt(position, target, up);


Neither direction.x and direction.y were 0, but up was still set to (0, 0, 1). What was the problem?

Answer:

There's a semi-colon right after the if()-clause. The code is basically this:

if(...);

{
    up.set(0, 0, 1);
}

It's an if-statement without a body. The curly braces are unrelated to the if-statement and don't really do anything here.


Not sure if that was obvious to everyone else, but it sure took me some debugging to find that... .___.

Myomyomyo.
Offline Damocles
« Reply #1 - Posted 2014-01-27 15:37:51 »

well: there is an angry face in the code:
1  
;{


always delete the angry faces!

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #2 - Posted 2014-01-27 15:39:31 »

Don't you just wish you had a debugger in your brain?

Why are all OpenGL tutorials written in Brainf**k?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2014-01-27 15:41:56 »

This won't really work.  Comparing floating point values with '==' or '!=' should have a very high stink value.  LookAt formulations degenerate as the direction approaches linear dependent (so approaching same and approaching opposite).
 
Offline xsvenson
« Reply #4 - Posted 2014-01-27 15:42:33 »

I'm not sure, but I think there might be possible for Eclipse to teach him, to warn about angry faces. Unless, they are in regular use as well, then it'd be annoying.

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline theagentd
« Reply #5 - Posted 2014-01-27 15:46:07 »

This won't really work.  Comparing floating point values with '==' or '!=' should have a very high stink value.  LookAt formulations degenerate as the direction approaches linear dependent (so approaching same and approaching opposite).
The direction is manually set, so it's very likely to be hardcoded to exactly straight down. I haven't had any precision problems with it so far, but yeah, might have to add a tolerance area.

Myomyomyo.
Offline Dxu1994
« Reply #6 - Posted 2014-01-27 15:52:16 »

IDEs like NetBeans & Eclipse warn about this..

Offline theagentd
« Reply #7 - Posted 2014-01-27 15:58:13 »

IDEs like NetBeans & Eclipse warn about this..
Weird, my Eclipse doesn't...

Myomyomyo.
Offline xsvenson
« Reply #8 - Posted 2014-01-27 16:01:55 »

You probably have to enable it in some settings

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2014-01-27 16:02:18 »

My Eclipse and Netbeans don't either. I use Netbeans at school and Eclipse at home and never once has either IDE warned me about frowny faces.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #10 - Posted 2014-01-27 16:31:27 »

There is no such warning for eclipse.
There ought to be D=

Why can I just open curly brackets ? Why is this allowed at all ? =/

Offline Rickmeister

Senior Member


Medals: 9
Projects: 1
Exp: 15 years


Don't eat yellow snow!


« Reply #11 - Posted 2014-01-27 16:42:45 »

IntelliJ warns about it, saved me a couple of times. Don't know about the rest of you, but even when writing text I tend to end lines with semicolons... Smiley
Offline Mike

JGO Wizard


Medals: 81
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #12 - Posted 2014-01-27 17:06:41 »

There is no such warning for eclipse.
There ought to be D=

There is a plugin called "FindBugs" that warns for it (among other potential issues like forgetting to close a stream). Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #13 - Posted 2014-01-27 17:45:47 »

That is a funny bug that happens to me as well. I have Eclipse and Intellij, and I don't get warnings for it either. Gonna start searching for some now Tongue

Is there really any practical use for
if(true);
that I'm not aware of?  Huh (Maybe it was just in there to troll debugging programmers Cheesy )

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2014-01-27 17:54:12 »

My code formatter (which executes every time I save), would have changed:

1  
2  
3  
         if(direction.x == 0 && direction.y == 0);{
            up.set(0, 0, 1); //Ensure up is not the same direction as "direction"
        }


to:

1  
2  
3  
4  
         if(direction.x == 0 && direction.y == 0);
         {
            up.set(0, 0, 1); //Ensure up is not the same direction as "direction"
        }


which would cause the alarm bells to ring immediately Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Dxu1994
« Reply #15 - Posted 2014-01-27 19:26:18 »

NetBeans:


Offline Roquen
« Reply #16 - Posted 2014-01-28 07:59:41 »

The eclipse warning for this will be "Empty flow-control statement".

Quote
is there really any practical use for if(true);
Yes: debugging.  Otherwise languages that are too strict about potential problems are quite annoying...try turning all all warnings that your IDE's compiler supports.
Offline xsvenson
« Reply #17 - Posted 2014-01-28 08:07:45 »

There is no such warning for eclipse.
There ought to be D=

Why can I just open curly brackets ? Why is this allowed at all ? =/

Curly brackets start a new scope. I've seen only a few times, this kind of scoping is used within a method body. As one would guess, You can live without it.

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #18 - Posted 2014-01-28 12:21:12 »

The eclipse warning for this will be "Empty flow-control statement".

Quote
is there really any practical use for if(true);
Yes: debugging.  Otherwise languages that are too strict about potential problems are quite annoying...try turning all all warnings that your IDE's compiler supports.

1  
2  
3  
4  
5  
6  
7  
8  
9  
public static boolean TRUE  = Math.random() < 1.0;
public static boolean FALSE = Math.random() > 1.0;

if(TRUE) {
   // stuff
}
else {
   // dead code, but no warning ^.^
}


Surprisingly useful, and allows you to make your compiler/ide as strict as possible.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline theagentd
« Reply #19 - Posted 2014-01-28 14:43:57 »

Surprisingly useful, and allows you to make your compiler/ide as strict as possible.
Lol, I read that as "makes your booleans truer". xD

Myomyomyo.
Offline Roquen
« Reply #20 - Posted 2014-01-28 15:08:48 »

@Riven: that's cute.  If java just had contacts that wouldn't work.  In my case I want a dead code warning, just in case...wow! I haven't heard that song in ages...that brings back memories!  Umm...what was I saying?

I was think more along the lines of a parameter hiding a field (mostly annoying, sometimes useful).  It's too bad that SuppressWarning tokens don't allow specialization (aka...sometime one token is disabling too many when I just want to suppress one)  Or the one that will complain about not writing all instance field accesses as: this.field.  Does anyone really like that sytle?  On second thought...don't tell me.
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.

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

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

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

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

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

BurntPizza (30 views)
2014-09-19 03:14:18

Dwinin (47 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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!