Strangest bug I've ever seen

There's only need for one forum for now. Discuss development. No advertising or thinly veiled attempts at advertising. Create a single thread for your project and be prepared to show and tell.
Post Reply
EighthDayAdvent
Posts: 33
Joined: Fri May 08, 2020 2:33 pm

Strangest bug I've ever seen

Post by EighthDayAdvent »

This doesn't matter too much because I was able to work around it, but it has me scratching my head.

I have a pointer to the human controlled player that does not get changed after startup, info_bar->humanPlayer.

When I assigned two pointers (I named them WTF because I was so frustrated) to point to that value, it came up as NULL in one and had value in the other. The odd part is the one that doesn't get used or evaluated in the next if() is always the one that has the value, where the other one that gets used is always assigned NULL.

This is equivalent to:

int x=6;

int a = x;
int b = x;

if(b).....

an when you check A, it is equal to 6 but when you check b it is 0. It only happens in release mode, not debug. The only thing I can think of is that it is a compiler optimization gone wrong or I am missing something.


User avatar
Deckhead
Site Admin
Posts: 89
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: Strangest bug I've ever seen

Post by Deckhead »

It doesn't look like you're missing anything to me.

But in the first image, I notice that you can't see the value of testWTF. In the second image I can see that testWTF is NULL but testWTF_again is seated correctly. In the first image, is testWTF also NULL?

In my experience, these sorts of errors are nearly always false-positives. Like the actual error is elsewhere in the code, you're overwriting an array, or using after free, or something; and this is just a symptom. I'm not sure what the equivalent tool on Mac is, but something like valgrind (Linux and I think Mac?), or Dr Memory (Windows/Linux) would show the original error. Google has an Address Sanitizer tool that does the same stuff.

Basically all these tools do is highjack the memory and tell you exactly where you're overwriting bounds or double deleting or something like that. They detect leaks as well.

You could also try enabling more compiler warnings. Finally, CPPCheck does a good
Developer of The Last Boundary and webmaster of IndieGameDev.net

EighthDayAdvent
Posts: 33
Joined: Fri May 08, 2020 2:33 pm

Re: Strangest bug I've ever seen

Post by EighthDayAdvent »

Deckhead wrote:
Wed Jun 24, 2020 1:18 am
It doesn't look like you're missing anything to me.

But in the first image, I notice that you can't see the value of testWTF. In the second image I can see that testWTF is NULL but testWTF_again is seated correctly. In the first image, is testWTF also NULL?

In my experience, these sorts of errors are nearly always false-positives. Like the actual error is elsewhere in the code, you're overwriting an array, or using after free, or something; and this is just a symptom. I'm not sure what the equivalent tool on Mac is, but something like valgrind (Linux and I think Mac?), or Dr Memory (Windows/Linux) would show the original error. Google has an Address Sanitizer tool that does the same stuff.

Basically all these tools do is highjack the memory and tell you exactly where you're overwriting bounds or double deleting or something like that. They detect leaks as well.

You could also try enabling more compiler warnings. Finally, CPPCheck does a good

Both images are the same run, and both testWTF and testWTF_again were set to point to the same location, info_bar.humanPlayer.

This shows its null in one, but not null in the other. That is why I called it WTF because I spent 20 mins tracking this down.

It also only happens in release mode and not debug mode.

I always start out assuming I missed something, but in this one, I have no idea what it is. I moved on though and rewrote it so it won't impact it.

Post Reply