Advertisement

Odd problem

Started by November 29, 2001 05:22 PM
8 comments, last by ATronic 23 years, 2 months ago
Hey, I''ve got this model format of mine. One thing it does looks like this.
  
GLfloat (*mesh)[3];
mesh = new GLfloat[polycount*3][3];
  
This part crashes every time a load a large model. The smallest one that has crashed this line is a 2881 polycount model. That would be allocating it like this.
  
mesh = new GLfloat[8643][3];
  
Is there some known reason as to why this would happen? Small models work just fine. I do not know exactly at what polycount it starts to crash, but I do know it''s big models that do it. Thanks for any help. Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Does it crash on allocation ?
Does it actually allocate the memory ?
Does it crash on access ?
What error does it crash with ?
Have you tried using a std::vector<> ? (passing &v[0] is backwards-compatible with C array arguments)
Have you tried using a struct instead of an array for the coordinates of an individual vertex ?
Can you see the fnords ?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
the problem may be that there is not enough contiguous memory for an array that size, so the allocation fails (do you check it?), and then the crash occurs later when you try to use that memory (which isn''t really there for you to use)
quote:
Original post by Bad Monkey
the problem may be that there is not enough contiguous memory for an array that size, so the allocation fails


mh. well I don''t think this would ever be a problem for any Pentium-class PC, since there surely IS a block of ~100K contiguous memory...
Hi.

I''m not sure that the syntaxis of the allocation is right.
You can try to change the allocation as follows :
GLfloat (*mesh)[3];
mesh = new GLfloat[polycount*3*3];

if that doesn''t work try with this one :

GLfloat (*mesh)[3];
mesh[0] = new GLfloat[polycount*3];
mesh[1] = new GLfloat[polycount*3];
mesh[2] = new GLfloat[polycount*3];


"If you''re gonna die, die with your boots on"
-It crashes on the first allocation
-It is correct syntax, works with smaller models
-It crashes within the block move when allocating vertex data
-I am posative of all of that

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Advertisement
Please direct any posts here.

http://www.gamedev.net/community/forums/topic.asp?topic_id=69019

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
quote:
Original post by Gelmir
I'm not sure that the syntaxis of the allocation is right



mesh is a pointer to an array of 3 floats, not an array of 3 pointers to float. ATronic's syntax IS correct.


ATronic : try malloc'ing a sufficiently large block of memory, then build your array inside it

void* ptr = malloc( sizof( GLfloat ) * polycount * 9 );if( !ptr ) throw( std::bad_alloc ); // Or something...mesh = new( ptr ) GLfloat[polycount*3][3]; 


If malloc succeeds then it is a layout problem rather than an allocation problem.

quote:
Original post by ATronic
-It crashes within the block move when allocating vertex data



Can you post the code copying the block ?


Edited by - Fruny on November 30, 2001 9:45:10 AM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Actually, if you look at the post I put the address to, you will see some other information. What happens is this. I allocate the memory using new. New ultimately calls malloc, which does it''s thing with the var pools and such. Then it goes to link_new_block. Then, in kernel32.dll the following is done.

BFF958F8:53 push
BFF7B498:F88B mov
BFF7A550: 0C4589 mov
BFF7A3D1:045089 mov

It gets to the last one and crashes.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Well, I''m afraid I can''t help you more : this works without a hitch on my machine (allocates 864 Mo)

#include int main(int argc, char* argv[]){	int count = 24 * 1024 * 1024;	float (*mesh)[3];	mesh = new float[3*count][3];		cout << (void*)mesh << endl;	mesh[0][0] = 12;	mesh[3*count-1][0] = 25;	cout << mesh[0][0] << " " << mesh[3*count-1][0] << endl;	delete[] mesh;	return 0;} 

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement