Forum

Weird ass thing

Discuss programming topics for any language, any source base. If it is programming related but doesn't fit in one of the below categories, it goes here.

Moderator: InsideQC Admins

Weird ass thing

Postby revelator » Tue Mar 19, 2013 3:11 pm

So im fiddling with my TQX engine and rebuild it well guess what debug builds Work fine but any hint of optimization crashes it wtf :lol:
Anyone got a hint on what the hell can cause such a thing ?
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby r00k » Tue Mar 19, 2013 4:27 pm

I seem to have the same problem, debug doesnt crash, though the release randomly crashes on map change. I think i have a null pointer somewhere in gl_rmisc.c.
I cant get the debug to crash, and when i latch on to the app it really doesnt offer much about the crash.

I'm in the process of taking a stable build and painstakingly adding the changes one feature at a time, then testing each build for a couple days (online gameplay too) until i find the point it crashes. :(
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Weird ass thing

Postby Spike » Tue Mar 19, 2013 5:40 pm

it should generally be possible to include debug information even with various optimisations.
or you can try running it via valgrind. that'll generally detect uninitialised stack variables and stuff.
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Weird ass thing

Postby r00k » Tue Mar 19, 2013 7:26 pm

is there a valgrind binary for windows 32?
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Weird ass thing

Postby revelator » Tue Mar 19, 2013 9:27 pm

there is but its buggy :/ better to use drmemory.
My tqx engine has a built in memory debugger but so far i have not been able to get anything relating to a null pointer from its output.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby revelator » Tue Mar 19, 2013 11:28 pm

ah speak of the devil the built in memory ddebugger finally fired

WARNING: Access out of range; SUFFIX of block sized 11 bytes, allocated at
4F220FA8 (no label) by function Z_Malloc (line 111 of
D:\Tq148X\zone.c) at Wed Mar 20 00:18:40 2013 using `malloc', has
been corrupted.

im using mh's cleaned up memory manager :S

explodes here

void *Z_Malloc (int size)
{
int *zblock = (int *) malloc(size + sizeof(int)); // kaboom yes this is highly irritating :(

if (!zblock)
{
Sys_Error ("Z_Malloc: failed on allocation of %i bytes", size);
}
memset (zblock, 0, size + sizeof (int));

zblock[0] = ZONEID;

return (zblock + 1);
}

It only happens once at start but its enough to crash it Cold on win7 with the latest patches. Im starting to Wonder if ms has gone ape on memory bugs ?? since lately some of my normally working games have stopped working, im also getting a bsod from time to time that points to a ram error but i checked the ram using memtest and several other tools and they all tell me my ram are ok. So maybe a bug in ms patches hmm.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby Spike » Wed Mar 20, 2013 3:44 am

if in windows+msvc, link against the debug msvc runtime rather than the release one, and sprinkle calls to _CrtCheckMemory throughout your code (even with optimisations enabled).
This will check all your malloc blocks for obvious memory corruption without sideeffects.
It won't help with stack errrors though.

microsoft have enabled dep (which breaks winquake) and they have changed their runtimes (so freeing stack memory is properly detected, but this needs you to relink against a more recent runtime).
microsoft just want your buggy programs to stop working.
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Weird ass thing

Postby frag.machine » Wed Mar 20, 2013 4:01 am

This

Code: Select all
int *zblock = (int *) malloc(size + sizeof(int));


Shouldn't be this instead ?

Code: Select all
int *zblock = (int *) malloc(size * sizeof(int));
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2060
Joined: Sat Nov 25, 2006 1:49 pm

Re: Weird ass thing

Postby Spike » Wed Mar 20, 2013 6:20 am

... are they not the same?
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Weird ass thing

Postby revelator » Wed Mar 20, 2013 9:25 am

heh funny that you noticed that i was also wondering about that one its indeed a + not a * it uses add not multiply symbol ???? hmm im going to try and change that and see what happens.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby revelator » Wed Mar 20, 2013 9:44 am

Ok it seems to be intended to use + instead i tried this and it seems to have fixed the corruption

int *zblock = (int *) malloc(sizeof(int) + ((size + 31) & ~31)); // hmm fixed the memory corruption by rounding it off to 32 bytes
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby Spike » Wed Mar 20, 2013 9:59 am

Your memory block is (mis?)aligned to an int. aligning the size of the alloc to 32 bytes is completely pointless because its still only got int alignment.
If that 'fixes' it then the issue is an overflow, and you should fix the caller and not hack the callee. Just randomly adding 32 to the result would have the same (possibly more robust) effect... Its a stupid thing to do though, just fix the caller instead!

sse would prefer 16-byte alignment instead of 4-byte alignment, but you need to align the start rather than the total size for it to be useful to sse.
Either way your code would probably be better if the int was an intptr_t instead, to keep things aligned in 64bit builds.

Side note:
Replacing Z_Malloc with an actual malloc like your code does may result in issues in 64bit builds as the location of certain zoned strings are no longer at a specific offset relative to the progs string table, or may cause issues with mods that use qccx hacks (but then pretty much everything might causes issues with that sort of mod, so meh).
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Weird ass thing

Postby revelator » Wed Mar 20, 2013 2:00 pm

hmm the codes not mine its mh's :s i was wondering about the int cast also i would have thought to use a byte ptr instead.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2518
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Weird ass thing

Postby frag.machine » Wed Mar 20, 2013 6:43 pm

Spike wrote:... are they not the same?


:!: :?:

Code: Select all
int *zblock = (int *) malloc(size + sizeof(int));

Code: Select all
int *zblock = (int *) malloc(size * sizeof(int));


let's say size = 100 and sizeof (int) = 4, then you're saying:

Code: Select all
100 + 4 == 100 * 4


I'm not trying to be ironic BTW, I actually fail to see how this can be the same.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2060
Joined: Sat Nov 25, 2006 1:49 pm

Re: Weird ass thing

Postby frag.machine » Wed Mar 20, 2013 6:48 pm

reckless wrote:Ok it seems to be intended to use + instead i tried this and it seems to have fixed the corruption

int *zblock = (int *) malloc(sizeof(int) + ((size + 31) & ~31)); // hmm fixed the memory corruption by rounding it off to 32 bytes


Quite complex, huh ? Also, seems it will kaboom again in 64 bit architecture, right ?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2060
Joined: Sat Nov 25, 2006 1:49 pm

Next

Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest