Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]General Pointer/Graphics Help plz  (Read 5849 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[SOLVED]General Pointer/Graphics Help plz
« Reply #15 on: May 06, 2010, 03:57:55 pm »
Hi again

Okay so I converted my base pointers to vectors using the method you provided above, but I'm getting the same problem (some sort of pointer/pixel data corruption).

So I created a small example so you can see what I'm trying to do.

Here's the original that works perfect:
Code: [Select]

    sf::Uint8* img_pal=new sf::Uint8(pal_max+1);

    for(int i=1;i<pal_max+2;i++)
    {
        img_pal[i]=pal[i-1];
    }
    return img_pal;


Here's a vector version that becomes corrupt later:
Code: [Select]

    sf::Uint8 temp2[pal_max+1];
    std::vector<sf::Uint8> pal_vct(*temp2,pal_max+1);
    sf::Uint8* img_pal=temp2;

    for(int i=1;i<pal_max+2;i++)
    {
        pal_vct[i]=pal[i-1];
        img_pal[i]=pal_vct[i];
    }

    return img_pal;

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED]General Pointer/Graphics Help plz
« Reply #16 on: May 06, 2010, 04:03:24 pm »
Quote
Code: [Select]
sf::Uint8 temp2[pal_max+1];

What is this fixed-size array for? It doesn't appear in the first piece of code.

Quote
Code: [Select]
std::vector<sf::Uint8> pal_vct(*temp2,pal_max+1);

It's vector(size, value). So here you end up with *temp2 values equal to pal_max+1 (don't you set the maximum level of warnings, so that your compiler can tell you that?).

If you really want the equivalent of the first example -- assuming that you meant "new[...]" not "new(...)", it's very easy:
Code: [Select]
std::vector<sf::Uint8> img_pal(pal_max+1);

for(int i=1;i<pal_max+2;i++)
{
    img_pal[i]=pal[i-1];
}
return img_pal;
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[SOLVED]General Pointer/Graphics Help plz
« Reply #17 on: May 07, 2010, 06:03:08 pm »
Hey again, thanks for the code as usual.

Sorry for the bad example, I included the pointer to allocate for the vector because it seemed to get the same results with or without so I thought I might as well include it.

Anyways the problem wasn't the vectors\.

I lost my original code I was converting when I overwrote it with another file by accident when code blocks crashed (and I just copy and pasted an example I saw online to test).

I found some old images from my original code (I saved out every pass) and found out the passes with my new code were accurate until a certain pass that corrupted them.

This part had a lot of extra stuff that needed to be added for the conversion, so rechecked and fixed it and now it works perfect.

Thanks again.