View unanswered posts | View active topics It is currently Tue Oct 21, 2014 2:32 pm



Reply to topic  [ 9 posts ] 
 devkitPSP error: can't use <stdio.h> 
Author Message

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
After several failed attempts at image loading done straight from a tutorials, I assumed it was a bug in their code, until I happened to use the file routines (fopen, fclose, etc.) myself and got the same error. And its not just those my code and the tutorials, the MP3 player, external PRX file, and all other examples that come with the kit that use those routines either won't compile period or don't work on the psp. 99% of the time they just won't compile.

PSP Specs: PSP OF v6.39 running TN-A Hombrew Enabler

If there's a fix for this, can someone please point me to it? I've trying to setup PSPSDK with Cygwin since 1pm (its now 1am) and haven't got squat. devkitPSP is so much easier to setup, but I need to able able to use those routines :(


Fri Jul 29, 2011 5:44 am
Profile
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1135
Location: UK
I've just updated devkitPSP and checked a few stdio examples which appear to work for me using HEN on 6.35. Hopefully r15 works for you, just run the updater and it should pick up the new version.

_________________
devkitPro IRC support
Personal Blog


Sat Jul 30, 2011 6:28 pm
Profile ICQ WWW

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
Sorry for double posting (couldn't find the edit button...), but I just figured I'd say the new release fixed it :)

There is one more thing though...Aparently, if you build a PRX EBOOT that uses <stdio.h>, it crashes the PSP. At first I thought it might have been because the stdio library only works with ELF EBOOT's, but I've seen several other signed homebrew such as Daedalusx64 that use libpng.


Tue Aug 16, 2011 1:16 am
Profile
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1135
Location: UK
Do you have code that crashes? Someone mentioned this a while ago but I couldn't reproduce the problem locally.

_________________
devkitPro IRC support
Personal Blog


Tue Aug 16, 2011 10:33 am
Profile ICQ WWW

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
Well it's not really a code issue. If I build the game as an ELF it works fine, but if I build the game adding

BUILD_PRX = 1

to the makefile while using any of the file managing routines from <stdio.h>, it'll crash when run on the psp.


Fri Aug 19, 2011 8:38 pm
Profile

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
(still can't find edit button...) I downloaded the PSPSDK right after that post and got the same issue when it compiled. I honestly say I'm confused :/ At this point, I think the easiest fix would be to just create my own custom stdio.h include using the PSP's built in sceIo functions. When I finish it, I'll post in case anyone else might want it.


Sun Aug 21, 2011 2:27 am
Profile
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1135
Location: UK
There's a time limit on editing, don't worry about double posting.

I've been having a play around and I still can't get this to crash, stdio also seems to work for me with BUILD_PRX=1 although after some more investigation it looks like it will fail if I also add USE_PSPSDK_LIBC=1. I tried changing PSP_FW_VERSION in the Makefile too but that had no effect.

I've attached the code I was playing with, the archive also has a precompiled EBOOT.PBP

Attachment:
File comment: simple stdio test example
filetest.tar.bz2 [81.16 KiB]
Downloaded 136 times

_________________
devkitPro IRC support
Personal Blog


Mon Aug 22, 2011 5:09 am
Profile ICQ WWW

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
I don't have my psp on me to test your code right this second, but for the most part the only diffence between your code and mine is that I use C++ and you use C. Now that I think about it, I think I remember hearing something somewhere about that being an issue...


Sat Aug 27, 2011 7:33 pm
Profile

Joined: Mon Nov 01, 2010 2:05 am
Posts: 19
:lol: Yep, that was the problem.

Once I converted my program to C, everything ran silky smooth. Although, there is one thing I can't get working...It compiles without any errors, but crashes on the psp:

Code:
#include <psptypes.h>
#include <malloc.h>
#include <stdio.h>
#include <png.h>

typedef u32 Color;
typedef int bool;
#define true 1
#define false 0

typedef struct {
   int width;
   int height;
   int realWidth;
   int realHeight;
   bool swizzled;
   Color* data;
} Texture;

static int getNextPower2(int width) {
   int b = width;
   int n;
   for (n = 0; b != 0; n++) b >>= 1;
   b = 1 << n;
   if (b == 2 * width) b >>= 1;
   return b;
}

void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg) {}

Texture* loadPNG(const char* filename) {
   png_structp png_ptr;
   png_infop info_ptr;
   unsigned int x, y, sig_read = 0;
   png_uint_32 width, height;
   int bit_depth, color_type, interlace_type;
   u32* line;
   FILE *fp;
   Texture* tmpTex = (Texture*) malloc(sizeof(Texture));
   if (!tmpTex) return NULL;
   tmpTex->swizzled = false;
   if ((fp = fopen(filename, "rb")) == NULL) return NULL;
   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
   if (png_ptr == NULL) {
      free(tmpTex);
      fclose(fp);
      return NULL;;
   }
   png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, user_warning_fn);
   info_ptr = png_create_info_struct(png_ptr);
   if (info_ptr == NULL) {
      free(tmpTex);
      fclose(fp);
      png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
      return NULL;
   }
   png_init_io(png_ptr, fp);
   png_set_sig_bytes(png_ptr, sig_read);
   png_read_info(png_ptr, info_ptr);
   png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, int_p_NULL, int_p_NULL);
   if (width > 512 || height > 512) {
      free(tmpTex);
      fclose(fp);
      png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
      return NULL;
   }
   tmpTex->realWidth = width;
   tmpTex->realHeight = height;
   tmpTex->width = getNextPower2(width);
   tmpTex->height = getNextPower2(height);
   png_set_strip_16(png_ptr);
   png_set_packing(png_ptr);
   if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
   png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
   tmpTex->data = (Color*) memalign(16, tmpTex->width * tmpTex->height * sizeof(Color));
   if (!tmpTex->data) {
      free(tmpTex);
      fclose(fp);
      png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
      return NULL;
   }
   line = (u32*) malloc(width * 4);
   if (!line) {
      free(tmpTex->data);
      free(tmpTex);
      fclose(fp);
      png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
      return NULL;
   }
   for (y = 0; y < height; y++) {
      png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
      for (x = 0; x < width; x++) {
         u32 color = line[x];
         tmpTex->data[x + y * tmpTex->width] =  color;
      }
   }
   free(line);
   png_read_end(png_ptr, info_ptr);
   png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
   fclose(fp);
   return tmpTex;
}


It worked when I was building ELF EBOOTs in C++, but now just adding the loadPng() function to my code causes it to crash. If you could point out any errors I've made it really get me out of a bind :)

PS:
Has anyone got a working version of the PRX Loader example?


Mon Aug 29, 2011 5:35 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at SourceForge.net. Fast, secure and Free Open Source software downloads