Skip to main content
GameDev.net gamedev.net
🔒 Locked

Can't seem to see the forest for the trees

Started by Indogo 2000 Aug 14, 2008 at 3:53 PM 44 replies 7.8k views
Original Post
Indogo 2000
Indogo 2000
SEEMS to be allocating just fine. Filling rbuf with values kills it. also crashes on DeleteRenderBuffers() I'm not a newb but this FAIRLY standard buffer implementation is driving me buggy. what very simple thing have missed? #include #include #include unsigned char ***rbuf; // to become rbuf[scrX][scrY][3] bool RBufsActive=FALSE; // to make sure we don't call one twice int scrX, scrY; // for the dynamic array int AllocRenderBuffers( void ) { int x, y; // we've been here without calling DeleteRenderBuffers() first if(RBufsActive==TRUE) return 0; // Allocate rbuf[x][y][3], the main render buffer if((rbuf=(unsigned char***)malloc(scrX*sizeof(unsigned char)))==NULL) return 0; for( x=0; x255 ) ch=0; // keeping ch in the 0-255 (unsigned char) range rbuf[x][y][c] = (unsigned char)ch; // fill it with something small } // we all know the "array value printout loop" lol for(x=0; x<scrX; x++) for(y=0; y<scrY; y++) for(c=0; c<3; c++) printf("%d ", rbuf[x][y][c] ); if(!DeleteRenderBuffers()) return(0); return(1); } getting the access violations at the line: rbuf[x][y][c] = (unsigned char)ch; ok am using: VS2005 4 gigs of ram and yes i should be spanked for my commenting. thanks guys in advance!
UncleRemus
UncleRemus
Hello,

I think you're making it too complicated.
Why don't you use a simple array with size scrX*scrY*3 ?

unsigned char * rbuf = (unsigned char *)malloc(scrX*scrY*3*sizeof(unsigned char));

or use C++

std::vector rbuf;


Uncle
jouley
jouley
Quote:
Original post by UncleRemus
I think you're making it too complicated.
Why don't you use a simple array with size scrX*scrY*3 ?

Seconded!
Quote:

or use C++

Thirded!

Also, the debugger is your friend, here. Step through, and see what fails. The values of everything leading up to this point will be invaluable.
Indogo 2000
Indogo 2000
stepped through with the debugger quite slowly. yep it's been a good friend lol
just haven't cought anything through it so far with this one (sigh).
uncle remus this vector thing is new to me. is it part of the standard c++ ?
i'll wander around this sight toof ore more on it. thx guys.

ps: i've gone three and for dimensional arrays like this before.
i'm pretty sure it was on the same compiler. must be getting old heh

empirical2
empirical2
Doing it that way is making things difficult. What if you want to access the table as a whole to say write to a file or copy it or something.

Much easier to do as above. scrX*SrcY*3
deadstar
deadstar
Quote:
Original post by Indogo 2000
this vector thing is new to me. is it part of the standard c++ ?


#include <vector>std::vector<unsigned char> rbuf;rbuf.push_back('a');rbuf.push_back('x');cout << "First value: " << rbuf[0] << endl;rbuf.clear();


Most useful tool I've ever encountered. Google for some more usage on it, like Iterating and such.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2   A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk
losethos
losethos
Umm... what happens if you do a multidimensional array access on a non-multidimensional-array variable?

If you wish to manually handle multidimensional arrays, do it like this:

char *a;

a[num_columns*row+col]=whatever.




or for a 3 dimensional array:

a[max_x*max_y*z+ max_x*y+x]=whatever.
Indogo 2000
Indogo 2000
ok guys. i suppose you're right about the one dimensional array method.
and you guys really have me intrigued about this std::vector deal.
was trying to resurrect some ancient (1995) voxel-terrain code I found from
one of my backup discs. very nastalgic. thanks guys for you insights!!!
haegarr
haegarr
Besides the tips above, in the OP's snippet there are at least 2 errors (I haven't looked furthur):

Instead of
if((rbuf=(unsigned char***)malloc(scrX*sizeof(unsigned char)))==NULL)
you have to allocate _pointers_ like here
if((rbuf=(unsigned char***)malloc(scrX*sizeof(unsigned char**)))==NULL)

And later on, instead of
if((rbuf[x]=(unsigned char**)malloc(scrY*sizeof(unsigned char)))==NULL)
you have to allocate _pointers_ like here
if((rbuf[x]=(unsigned char**)malloc(scrY*sizeof(unsigned char*)))==NULL)

The 3rd allocation is correct so far.
Indogo 2000
Indogo 2000
ah HAH!!
that was EXACTLY the embarrasingly simple oversight i was hoping it would be
yay i'm not cray lol
works like a charm


thx haegar.
you guys all rock
jouley
jouley
Quote:
Original post by Indogo 2000
ah HAH!!
that was EXACTLY the embarrasingly simple oversight i was hoping it would be
yay i'm not cray lol
works like a charm


thx haegar.
you guys all rock

So now you've learned a lesson and will use std::vectors, right? [smile]
Indogo 2000
Indogo 2000
you definitely got me curious enough to check out
the std::vector mechanism Jouley! i've started poking at it.
what about performance though?
Spoonbender
Spoonbender
Quote:
Original post by Indogo 2000
you definitely got me curious enough to check out
the std::vector mechanism Jouley! i've started poking at it.
what about performance though?

In principle, identical to raw arrays.
Indexing into the array typically gets inlined by the compiler so it is as efficient as if it'd been a regular array.

If you're using MSVC 2k5 or later though, Microsoft has added a bit of overhead to it, by doing bounds-checking by default. That can be disabled by defining the right macro however, and usually the performance hit from this bounds-checking is negligible in any case.
Indogo 2000
Indogo 2000
nice to have the bounds checking at first...
nice to be able to take control of it when you start zeroing in where and when
you can use it better elsewhere.
Indogo 2000
Indogo 2000
hey how do we put our code snippets inside thoes nice scrollable boxes?
haegarr
haegarr
Wrap them by [ source ] and [ /source ] tags, but leave out those spaces inside the brackets.
Indogo 2000
Indogo 2000

It may sound wierd but i'm working to DEoptimize
the ray casting mechanism to just regular vector math.
Yep it'll be painfully slow. I will then be porting the
routines to run in parallel on the GPU via CUDA. Was thinking
of a way to implement the paralelism.
Ok a few ways come to mind but trying to send even just
a 512x512 heightmap to each gpu would be way too much.

So I was thinking of like a supervoxel. say 8x8x8 segments.
Using a 3d no-hit-test bresenhams-line-algorithm to make a
slice of data to pass to the gpus. they would each hit test
their own low-res supervoxel, flagging it as having data or not.
The supervoxels actually HAVING data would be sent BACK to
the gpus for voxel level hit-testing. I know it seems like a lot
of extra work but when the voxel data starts getting even bigger
it seems like it would pay off even more.
losethos
losethos
Who pays you to push the stl library vector stuff? I find a lot of people who teach it as some kind of gospel. Who here agrees with me?
losethos
losethos
IoIndigo? You thumping your chest?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.