Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (731)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (798)
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  
  Silly Programming Mistakes  (Read 1926 times)
0 Members and 1 Guest are viewing this topic.
Offline Ecumene

JGO Kernel


Medals: 184
Projects: 3
Exp: 8 years


I did not hit her! I did not!


« Posted 2017-04-11 23:50:01 »

I've been making some silly mistakes lately.

Post your recent mistakes in this thread, and how long it took you to fix it.
I'll start:

1  
2  
hashMap.get(myString) = myObject
hashMap.get("" + myString) = null

Took me almost an hour!

Offline CoDi^R
« Reply #1 - Posted 2017-04-12 08:03:37 »

1  
boolean filtered = filter.apply(this, cy, cy, h);


1  
camera.position.set(cameraIY, cameraIY, 0.0f);


Both last week. Both took more than half an hour. And both could have been spotted much earlier if my variable naming decisions would not deny the capabilities of IntelliJ's code introspection ("parameter 'x' is named 'y', are you crazy or just short on caffein?").

Robotality - steamworks4j - @code_disaster - codi^r @ #java-gaming
Offline dfour
« Reply #2 - Posted 2017-04-12 10:29:31 »

1  
2  
3  
4  
5  
6  
7  
8  
fbPostEffects = new FrameBuffer(Format.RGBA8888,this.sw,this.sh, false);

fbPostEffects.begin();
...
fboPostEffects.end();

renderTexture = fboPostEffects.getColorBufferTexture();
fboPostEffects.dispose();


Yesterday I created a FrameBuffer for adding some shader effects and disposed it before using it. Spent about 45 minutes wondering why my screen was black.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cygnus

Senior Newbie


Exp: 1 year



« Reply #3 - Posted 2017-04-13 01:33:53 »

1  
2  
int absoluteWidth = (int) (o.getWidthScale() * image.getWidth() * scaleWidth);
int absoluteHeight = (int) (o.getWidthScale() * image.getWidth() * scaleWidth);

Can you spot the mistake?
Offline DarkCart

JGO Kernel


Medals: 121
Projects: 9
Exp: 50 years


It's all in the mind, y'know.


« Reply #4 - Posted 2017-04-13 01:37:21 »

1  
2  
int absoluteWidth = (int) (o.getWidthScale() * image.getWidth() * scaleWidth);
int absoluteHeight = (int) (o.getWidthScale() * image.getWidth() * scaleWidth);

Can you spot the mistake?

Oh, the joys of copypasting while forgetting to change what you copypasted.

The darkest of carts.
Offline cygnus

Senior Newbie


Exp: 1 year



« Reply #5 - Posted 2017-04-13 02:58:14 »

God yes. So fun.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1284
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2017-04-13 07:13:28 »

I've been making some silly mistakes lately.

Post your recent mistakes in this thread, and how long it took you to fix it.
I'll start:

1  
2  
hashMap.get(myString) = myObject
hashMap.get("" + myString) = null

Took me almost an hour!
That only breaks if myString is null, and putting null keys in your maps is... questionable, usually Smiley

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

JGO Kernel


Medals: 184
Projects: 3
Exp: 8 years


I did not hit her! I did not!


« Reply #7 - Posted 2017-04-13 15:34:46 »

That only breaks if myString is null, and putting null keys in your maps is... questionable, usually Smiley

Hmm, good point as I think about this more..
I should probably check if the string is null anywhere, that could cause a lot more trouble.

Really the empty string in the OP is a second string added to myString, its finding X file in Y folder. For the root it supposed to be empty (""). Putting myString in by itself and then trying to find plus the empty folder string later was the problem.. Idk why checking for the folder being empty or not, then just searching for the myString fixed it. (So maybe myString isnt null)

Offline CoDi^R
« Reply #8 - Posted 2017-04-23 21:07:12 »

Doing a small side project with Direct State Access (DSA) in "modern" GL 4.5. About an hour of my life I won't get back...  Roll Eyes

Robotality - steamworks4j - @code_disaster - codi^r @ #java-gaming
Offline SHC
« Reply #9 - Posted 2017-04-24 09:24:02 »

Am making a tower defense game, and I decided to make the turrets fire to the nearest point in the path of enemies. Then I also wanted to do optimized code, that is, the nearest point will only be computed on the creation of the turret and not with every projectile created.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
if (nearestPathPoint == null)
{
    nearestPathPoint = path.get(0);

    for (Vector2 pt : path)
        if (pt.distanceSquared(this.position) < nearestPathPoint.distanceSquared(this.position))
            nearestPathPoint = pt;
}

// Now fire projectile towards nearestPathPoint after timer

But when creating the turrets, all turrets are firing towards same point. Then after an hour I realized, that I accidentally declared nearestPathPoint as static when it shouldn't be. Precious amount of time in LudumDare JAM.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 906
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2017-04-24 09:56:04 »

That's why I set syntax colouring up so that static vars and methods appear in a completely different colour Smiley

Cas Smiley

Offline SilverTiger

JGO Coder


Medals: 40
Exp: 3 years


がんばってください!


« Reply #11 - Posted 2017-04-24 10:18:34 »

While learning Vulkan I checked every result with assertions. This line of code compiled successfully:

1  
2  
3  
4  
5  
6  
7  
/* Create the vertex shader module */
VkResult result = vkCreateShaderModule(device, &vertexCreateInfo, nullptr, &shaderModules[0]);
assert(result == VK_SUCCESS);

/* Create the fragment shader module */
result = vkCreateShaderModule(device, &vertexCreateInfo, nullptr, &shaderModules[1]);
assert(result == VK_SUCCESS);

When trying to create the graphics pipeline, the validation layers stated, that there's no entry point named "main" in the fragment shader.
Double checked it and compiled the fragment shader to SPIR-V again. Same error message... took me some time to realize the mistake occured when creating the shader modules.

Online theagentd

« JGO Bitwise Duke »


Medals: 983
Projects: 4
Exp: 8 years



« Reply #12 - Posted 2017-06-04 21:30:47 »

Did this one today:
1  
BufferedImage tilesetImage = ImageIO.read(new File("test resources\tilesets\tileset.png"));

Myomyomyo.
Offline kingroka123
« Reply #13 - Posted 2017-06-04 22:01:41 »

I've recently been working with JavaScript specifically NodeJS and I wrote something like this:
1  
2  
3  
app.get("/", new function(req, res){
//do something
});


took me longer that I'm willing to admit to find the mistake Stare

Answer in case you're as stuck as i was: removing the "new" in front of function fixes the code. The new makes the function run immediately as opposed to running when the user goes to the "/" route
Offline SHC
« Reply #14 - Posted 2017-06-05 06:08:10 »

In case you don't know, Node supports the async await pattern, so you could easily eliminate callback hell by using it with promises. Combined with Mongoose, I'd write

1  
2  
3  
4  
5  
app.post('/login', async (req, res) =>
{
    let user = await users.findOne({ "uid": req.body.uid }).exec();
    // Do something with the user
});


The mistake possible here, is it you forget the await keyword, you'd get a Promise instead of the value which you'd expect. Took me an hour to find this.

Offline jonjava
« Reply #15 - Posted 2017-06-05 07:17:55 »

Only since 7.6. And if you got callback hell you're probably doing something wrong to begin with.

Not that there's anything wrong with Promises (async/await) per se as long as you know what you're doing.

@kingroka123

You should avoid using the 'new' keyword entirely, it's not necessary (unless some odd api requires it for some god forsaken reason).

Offline KaiHH

JGO Kernel


Medals: 416



« Reply #16 - Posted 2017-06-05 07:42:40 »

The mistake possible here, is it you forget the await keyword, you'd get a Promise instead of the value which you'd expect. Took me an hour to find this.
The next mistake there is that if you do not wrap the await call in a try-catch (and handle it by possibly forwarding the error to next() - third parameter of the callback function) you'll get an uncaught promise rejection error when the promise rejects, and that'll cause Node to exit.
Offline SHC
« Reply #17 - Posted 2017-06-05 10:19:28 »

I know the need of using try catch to catch the errors, but not the next parameter. As far as I'm aware, the next parameter is only present in the middlewares in express.

1  
2  
function (req, res, next)
    // call next to begin calling the middleware described next


But in case of route handlers, there is no next parameter as far as I know. Am I wrong somewhere?

Offline KaiHH

JGO Kernel


Medals: 416



« Reply #18 - Posted 2017-06-05 11:00:58 »

Yes, you can use next, because the routing functions accept Middleware functions (and only Middleware functions) themselves. it's just that most people leave out the next parameter, because it's not needed in synchronous code (you could just as well throw an error there).
Pages: [1]
  ignore  |  Print  
 
 

 
Archive (336 views)
2017-04-27 17:45:51

buddyBro (535 views)
2017-04-05 03:38:00

CopyableCougar4 (978 views)
2017-03-24 15:39:42

theagentd (1014 views)
2017-03-24 15:32:08

Rule (993 views)
2017-03-19 12:43:22

Rule (973 views)
2017-03-19 12:42:17

Rule (971 views)
2017-03-19 12:36:21

theagentd (1071 views)
2017-03-16 05:07:07

theagentd (990 views)
2017-03-15 22:37:06

theagentd (760 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!