User forums > General (but related to Code::Blocks)

Compile error

<< < (3/5) > >>

sethjackson:
Ok I'll check it out tomorrow hopefully.  :lol:

sethjackson:
I tried


--- Code: (cpp) ---static_cast<unsigned char* []>(data) += 4;

--- End code ---

and it didn't work.


--- Code: ---error: invalid static_cast from type `unsigned char*[((unsigned int)((int)imageSize))]' to type `unsigned char*[]'

--- End code ---

What type (int, char, etc.) do I need to cast to???

sethjackson:
Nevermind. This works, and better too I think. :)


--- Code: (cpp) ---if (image.HasAlpha())
{
        unsigned long imageSize = image.GetWidth() * image.GetHeight() * 4;
        unsigned char* imageData = image.GetData();
        unsigned char* imageAlpha = image.GetAlpha();
        unsigned char* data = new unsigned char[imageSize];

        for (unsigned long index = 0; index < imageSize; index += 4)
        {
            memcpy(data, imageData, 3);

            imageData += 3;

            memcpy(data + 3, imageAlpha, 1);

            ++imageAlpha;

            data += 4;
        }

        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(),
                          GL_RGB, GL_UNSIGNED_BYTE, data);

        delete[] data;
}

--- End code ---

Michael:
Hello,

When you use new you should check if the memory has been reserved or not. If I remember correctly the new sends a bad_allocation exception if it fails. Another version of new just a null pointer (which could or not be a better alternative :)).

Best wishes,
Michael

killerbot:

--- Quote from: Michael on February 07, 2006, 10:42:10 am ---Hello,

When you use new you should check if the memory has been reserved or not. If I remember correctly the new sends a bad_allocation exception if it fails. Another version of new just a null pointer (which could or not be a better alternative :)).

Best wishes,
Michael


--- End quote ---

Normally when new fails, it throws -> catch it.
There exist a no_throw new. I think it is not portable, the gurus (Sutter, ..) give the advice not to use it. So just forget you ever heard about it ;-)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version