# Hang up at constructing of CPVRTexture(CPVRTextureHeader& sHeader, void\* pData)

**URL:** <https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601>\
**Category:** PowerVR Insider\
**Created:** [December 7, 2012, 6:43am UTC](https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601 "2012-12-07T06:43:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshihirotomaru](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@yoshihirotomaru](https://forums.imgtec.com/u/yoshihirotomaru)\
**Post date:** [December 7, 2012, 6:43am UTC](https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601/1 "2012-12-07T06:43:50Z")

</div>

I try to make RGB8888-format&nbsp;image to PVRTC4bit-format image.

  

Then, I prepared the "PVRTextureHeaderV3" and the data of RGB8888-format&nbsp;image,

  

and converted it by CPVRTCTexture(CPVRTextureHeader& sHeader, void\* pData).

  

But, when&nbsp;constructoring of CPVRTCTexture, the program hung up.

  

The odd thing is that there are some conditions of hangup as below.

  

1. VStudio-Debug Mode && MipMapLevel = more than 1(only 1 is OK) &&&nbsp;ImageWidth or Height = 512 and more(256 and less is OK)

  

2. VStudio-Release Mode(I don't know if any other condition is involved)

  

I wait for some advises.

  

&nbsp;

  

For reference, I write&nbsp;the source code and the environment.

  

SDK : OpenglES v2.10 for windows x86 emulation, PC:Windows XP 32bit (memory is enough)

  

IDE : Visual Studio 2008(using MFC)

  

Source Code:

  

unsigned char\* l\_pImageData[WIDTH\*HEIGHT\*4]; //pixel values are set

  

//Making of Header

  

&nbsp;PVRTextureHeaderV3 l\_cHeader;

  

&nbsp;l\_cHeader.u32Version = PVRTEX3\_IDENT;&nbsp;&nbsp;&nbsp;&nbsp;//Version

  

&nbsp;l\_cHeader.u32Flags = PVRTEX3\_PREMULTIPLIED;&nbsp;&nbsp;&nbsp;//Flags

  

&nbsp;l\_cHeader.u64PixelFormat = PVRStandard8PixelType.PixelTypeID;&nbsp;//PixelFormat

  

&nbsp;l\_cHeader.u32ColourSpace = ePVRTCSpacelRGB;&nbsp;&nbsp;&nbsp;//ColourSpace

  

&nbsp;l\_cHeader.u32ChannelType = ePVRTVarTypeUnsignedByteNorm; //ChannelType

  

&nbsp;l\_cHeader.u32Height = HEIGHT;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Height

  

&nbsp;l\_cHeader.u32Width = WIDTH;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Width

  

&nbsp;l\_cHeader.u32Depth = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Depth

  

&nbsp;l\_cHeader.u32NumSurfaces = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//NumSurfaces

  

&nbsp;l\_cHeader.u32NumFaces = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//NumFaces

  

&nbsp;l\_cHeader.u32MIPMapCount = 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//MipMapCount

  

&nbsp;l\_cHeader.u32MetaDataSize = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//MetaDataSize

  

&nbsp;//Create Texture

  

&nbsp;CPVRTexture l\_cOrgTexture(l\_cHeader, l\_pImageData); \<--[hang-up step]

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [December 7, 2012, 11:19am UTC](https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601/2 "2012-12-07T11:19:48Z")

</div>

Hi Yoshihiro,  
  
The reason you get a hang when you’re constructing the data with anything other than one MIP-Map is because the value passed in here tells the constructor how much memory to allocate/copy. When you pass in your data, it tries to copy enough data to fill all your MIP-Map levels. Since you’ve only allocated enough for the top level, it will cause an exception when attempting to copy the second MIP-Map.  
  
If you’re just trying to allocate the space, you should simply pass in NULL rather than a pointer, as the constructor will allocate enough data for you.   
  
If you’re copying in actual image data, you should set the properties to that of the image data you pass in (so if your image has one MIP-Map, just set it to one MIP-Map). To generate MIP Maps you should call pvrtexture::GenerateMIPMaps() with appropriate arguments.  
  
I hope that helps?  
  
Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![yoshihirotomaru](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@yoshihirotomaru](https://forums.imgtec.com/u/yoshihirotomaru)\
**Post date:** [December 10, 2012, 2:04am UTC](https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601/3 "2012-12-10T02:04:10Z")

</div>

Hi Tobias,

  

Thank you for your quick reply!!

  

I&nbsp;tried to make the all MipMaps with referring to your advise, and I could do it normally!!

  

I appreciate your assistance.

  

&nbsp;

  

P.S.

  

I'd like to get the size of the created PVRTC data.

  

So I&nbsp;save the data to a pvr file with saveFile(), and measure the file size....(it's not a big problem)

  

Is there any other efficient way to get the size.....mm

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [February 5, 2013, 9:35am UTC](https://forums.imgtec.com/t/hang-up-at-constructing-of-cpvrtexture-cpvrtextureheader-sheader-void-pdata/1601/4 "2013-02-05T09:35:59Z")

</div>

Hi Yoshihiro,  
  
  
  
Apologies, I missed your question at the bottom of this post last time I looked. There is an alternative way, adding the values of:  
  
CPVRTextureHeader::getDataSize() + CPVRTextureHeader::getMetaDataSize() + PVRTEX3\_HEADERSIZE  
  
  
  
will give you the full file size for any data type.  
  
  
  
Regards,  
  
Tobias
