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

large array crashes program..

Started by Xero-X2 Aug 9, 2002 at 12:03 AM 6 replies 950+ views
Original Post
Xero-X2
Xero-X2
ok in a simple opengl bitmap loading function I am createing an array for colors and an alpha channel,
GLubyte *data; //create pointer to memory
data = new GLubyte[sizeX*sizeY*4]; // Bitmap is x*y*4 bits/pixel
    
then after this in the program later when I scroll down on my little map it will crash if I go down to far on the Y axis. it took some hunting to find that the above was the cause. I confirmed it by changing the 4 to a 3 like below.
GLubyte *data; //create pointer to memory
data = new GLubyte[sizeX*sizeY*3]; // Bitmap is x*y*3 bits/pixel
    
so this would lack the Alpha channel I want, but this does not cause the program to crash. Any ideas about what would cause this or how I could fix it? if you would like more information just ask. EDIT: PS. I thought I might add the error that my program throws, The exception Floating-point invalid operation. (oxc0000090)occurred in the applicatoin at location 0x00407b71. followed by the same error again and the followed by The exceptoin unknown software exception (oxc0000027)occurred in the application at location 0x77e9bc2d [edited by - Xero-X2 on August 9, 2002 1:33:39 AM]
"I seek knowledge and to help those who also seek it"
tebriel
tebriel
It's late and I just may have no clue what I'm talking about now, but why are you using a pointer to a pointer?

Instead, won't this work?


GLubyte data; //create pointer to memory
data = new GLubyte[sizeX*sizeY*4]; // Bitmap is x*y*4 bits/pixel


Assuming I haven't had too much coffee tonight...

I'm assuming that GLubyte is a type of pointer and not some data type or struct/class, otherwise you should have to make it GLubyte* data;

[edited by - Tebriel on August 9, 2002 1:23:18 AM]
Xero-X2
Xero-X2
It appears that I am tired as well and I just made a bunch of mistakes typeing it in. I edited the first post so now its better, thanks for pointing my typo out.

[edited by - Xero-X2 on August 9, 2002 1:25:28 AM]
"I seek knowledge and to help those who also seek it"
tebriel
tebriel
Ahh... so assuming GLubyte isn't a pointer type--what I said should still work, yes?

Edit:

Oh, well with that edit it's looking alot better.

(Too many edits/posts in a short period of time!)

I'm not an OpenGL person so I can't see a problem with that code as it is now...hmm.

[edited by - Tebriel on August 9, 2002 1:28:00 AM]
Ronin_54
Ronin_54
First thing that I am wondering about...

Euhms... those should be 4 & 3 *bits* per pixel I think.

4 bits-per-pixel = 16 colors
3 bits-per-pixel = 8 colors

Shouldn''t it be bytes...? ^_^
benjamin bunny
benjamin bunny
Yes, he means bytes. I don''t think that''s the problem though.

I can''t see a problem with the code. Allocating an array of bytes of size width*height*numChannels is correct, and there''s no reason why allocating a smaller array should solve the problem. The only reason the larger array might be a problem would be if width and height were stupidly large, but then a bad-alloc exception would be thrown by new. I suspect the problem lies elsewhere in the code.

The exception Floating-point invalid operation wouldn''t seem to apply to this problem at all, seeing as we''re dealing with bytes, not floats. Without looking it up, I would guess it means the result of some floating point calcuation is NaN. I suggest you check your maths code. Running in debug mode, you should be able to see which line of code threw the exception.

____________________________________________________________
www.elf-stone.com
Xero-X2
Xero-X2
I finally got what threw the exception, it was
 glTexCoord2f(0.5f,0.5f);  

all of the
glTexCoord2f(0.5f,0.5f); 
in the program start throwing that exception any one have any idea why it would do that???
"I seek knowledge and to help those who also seek it"
Xero-X2
Xero-X2
*BUMP*
"I seek knowledge and to help those who also seek it"

Topic Locked

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

Sign in to reply to this topic.