forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

It cannot allocate enough memory, ok, now how to fix it?????

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Wed Jul 12, 2006 5:54 pm    Post subject: It cannot allocate enough memory, ok, now how to fix it????? Reply with quote

Id really really really love to get an answer to this as this is the only thing stopping my world from rendering :( ...

Here is the code pertaining to the error recieved.

Code:

/* Image type - contains height, width, and data */
typedef struct {
    unsigned long sizeX;
    unsigned long sizeY;
    char *data;
} Image;

// Load Texture
Image *textures[5];
int sg;
for(sg=0;sg<5;z++) {
     // allocate space for texture
     textures[sg] = (Image *) malloc(sizeof(Image));
     if (textures[sg] == NULL) {
             printf("Error allocating space for image");
                 exit(0);
     }
}

Im reciveing the error that he allocation of the memory for hte image failed... (PSPLink printed it if that matters)

Ok, now that i know i cannot allocate the memory... Now what do i do to enable myself to allocate the memory of the Image structure?
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Wed Jul 12, 2006 6:34 pm    Post subject: Reply with quote

There's nothing wrong with the snippet you posted. I suspect somewhere earlier on you've written over the end of a previous allocation and corrupted the heap.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Wed Jul 12, 2006 7:15 pm    Post subject: Reply with quote

Danzel said something of the sort. Oh and the textures is an array of 5 integers if that helps...

GLint textures[5];

So your saying somewhere before my malloc call there is something corrupting the stack... Any hints on what could?
Back to top
View user's profile Send private message
bada



Joined: 27 Apr 2006
Posts: 4

PostPosted: Wed Jul 12, 2006 9:01 pm    Post subject: Reply with quote

Code:

for(sg=0;sg<5;z++) {
     // allocate space for texture
     textures[sg] = (Image *) malloc(sizeof(Image));
     if (textures[sg] == NULL) {
             printf("Error allocating space for image");
                 exit(0);
     }
}


hmm - look - z++ - so you have infinite loop and he take all memory

IMHO also its better use mamalign(16, sizeof(Image)) instean fo malloc
Back to top
View user's profile Send private message
siberianstar



Joined: 22 Jun 2006
Posts: 70

PostPosted: Wed Jul 12, 2006 10:02 pm    Post subject: Reply with quote

ahah z++! xD
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Jul 13, 2006 1:08 am    Post subject: Reply with quote

bada wrote:
IMHO also its better use mamalign(16, sizeof(Image)) instean fo malloc
malloc() is already 16-byte aligned. See http://forums.ps2dev.org/viewtopic.php?t=3601
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Thu Jul 13, 2006 5:56 am    Post subject: Reply with quote

Ahhh thanks for that! But that really shouldnt matter will it? Since it doesnt even allocate the first time around? But im changing it.

Also, what should i use then? memset or malloc? W/e you guyz think is best. Danzel says malloc as i have it already.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Thu Jul 13, 2006 6:24 am    Post subject: Reply with quote

sg57 wrote:
Ahhh thanks for that! But that really shouldnt matter will it? Since it doesnt even allocate the first time around? But im changing it.

Also, what should i use then? memset or malloc? W/e you guyz think is best. Danzel says malloc as i have it already.


memset and malloc are completely different, so what's that for an question?

Besides, not your initial malloc fails, but this (endless) loop allocates a new block overwriting the pointer at textures[0] until sometime it runs out of memory and spits out your error string. So that's your luck that you have that check inserted, or else it would just loop forever until you hardreset your psp.
Back to top
View user's profile Send private message Visit poster's website
zilt



Joined: 21 Feb 2006
Posts: 45
Location: Ontario, Canada

PostPosted: Thu Jul 13, 2006 6:49 am    Post subject: Reply with quote

sg57 - you'll learn eventually that you can't just cut & paste code all the time and assume it'll work without even understanding what it does. As Raphael said, memset and malloc perform two entirely different functions and shows a fundamental lack of understanding of those features. After your little stunt on qj, I thought you might have learnt a lesson - but I guess not.
_________________
"We are dreamers, shapers, singers, and makers. We study the mysteries of laser and circuit, crystal and scanner, holographic demons and invocations of equations. These are the tools we employ and we know... many things." -- Elric, B5
Back to top
View user's profile Send private message Visit poster's website
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Thu Jul 13, 2006 7:48 am    Post subject: Reply with quote

Omg shut up about that. First, I DIDNT know a tutorial or w/e was out for that. I saw it at Cprogramming.com and as a little experiement converted it to work on the PSP. As for the 'from scratch' part, i added a fully transparent wireframe inside the robot and rotated those. Not really verticies and such like skeletal. when i thought it was skeletal animations, I called it my own, but i saw i was wrong, and now its been over with.

Second, its working now.

Third, I was also being told to use memset above if you read, and no im not an expert like some, so ill ask questions on what to do in cases i havent been in before, so be easy.

Fourth, people are assuming I was begging the brain dead blogger for posting that on front page. Raphael definitely has assumed this as he said over there. I never asked, nor want front page at all as its as over rated as LUA apps getting front page. ( "this deserves front page", "front pager right here" , etc. ).

On topic... Thank you for informing me on switching the z to sg (not really as it was an example) but thanks alot, its all working well, just some clipping and z-clipping ( :( ) which ill hide with fog. So thanks!
Back to top
View user's profile Send private message
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Thu Jul 13, 2006 10:01 am    Post subject: Reply with quote

Quote:
Third, I was also being told to use memset above if you read

Just going to defend myself here, I told you on irc that memset does not perform the same function as malloc and that you couldn't use it to replace malloc.
I did however tell you that using malign instead of malloc would not fix the problem. I think you've got these two mixed up.

I did totally miss the z++ error in the loop however, lmao.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Thu Jul 13, 2006 11:12 am    Post subject: Reply with quote

sg57 wrote:
Raphael definitely has assumed this as he said over there.

Dude, you really start to annoy me (not only here). First, because I didn't bring this up here, so refering me is just shoving the insults on you to someone other.

Second:
Raphael@qj.net wrote:

SG57@qj.net wrote:

Yeah Raphael, thats it, I was kissing the bloggers shoes for front page.

Funny how you turn the words inside my mouth
I never said anything like that. I only said how most people and even bloggers (known to do not-that-well research on their posts) fell for your announcement.


Start really reading posts, instead of just having a glimpse over them and brabbling nonsense.
Back to top
View user's profile Send private message Visit poster's website
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jul 13, 2006 1:28 pm    Post subject: Reply with quote

Drama content has reached dangerous levels!

Locked for posterity. Take it to private messages, please.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group