octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: uint8NDArray


From: Jordi Gutiérrez Hermoso
Subject: Re: uint8NDArray
Date: Fri, 26 Jul 2013 14:57:30 -0400

On 26 July 2013 14:52, Andrej Lojdl <address@hidden> wrote:
> I'm using uint8NDArray in my code, but there seems to be some kind of
> problems.
> Can any one who worked with this data type take a look and assume what the
> problem can be. I'm not expecting direct answers, but more some pin points
> on what to look.
>
>
> uint8NDArray data;
>
> std::ifstream file;
>
>  // read data from PPM file to Array for OpenGL rendering
>
>       file.open("default.ppm");
>
>       std::cout<<"--READING--"<<std::endl;
>
>       file>>magic_number>>skip;
>
>       std::getline(file, comment);
>
>       file>>width>>height>>max_color;
>
>       // reading the data, row by row
>
>       for(int j=0; j<width; j++)
>
>         {
>
>           for(int i=0; i<height; i++)
>
>             {
>
>               file>>data(0,i,j); //red

This is a nasal demon:

    http://en.wikipedia.org/wiki/Nasal_demon

You need to allocate space for uint8NDArray. It does not
bounds-checking by default, so you're just writing to uninitialised
memory. You have to pass a dim_vector to the uint8NDArray constructor
saying what size you want the array to be before you start writing to
it.

- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]