/* 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?
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.
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
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.
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
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!
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.
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.
[email protected] 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.