Mail Archives: djgpp/1999/09/13/19:32:52
Mikko Lehtonen wrote:
>
> Hello!
>
> I have two things:
>
> 1.
> I code in win98 dosbox quite happily, without problems etc. but then I
> tried in clean win98 dos.. (dos7?) without the gui loaded, and a problem
> raised!
> first it told me that there's no dpmi. ah okey, I forgot this, I
> put cwsdpmi in the dir.. the machines hangs.. and with little more poking,
> I find that every time I trie to use cwsdpmi, my machine hangs! (no, not
> in win98 dosBOX when it says protected mode not accesible, which is
> because of win98's dpmi service ?)
> has microsoft done a another stupid mistake or have I missed something?
>
> 2.
>
> I have this program that moves couple of cool lights around on the screen,
> and then I pondered, that a background could be cool.. so I wrote a fast
> opentga routine which wasn't completely ripped, but it was some..
> the strangest thing happened when playing around with this code!
> fclose(fp); doesn't work, it crashes the program, free(backg); doesn't
> work, crashes the program, and if I have neither of them, it crashes in
> the end anyways.
>
> small peezes of code:
> (its in vesa2 btw.)
>
> unsigned int *backg;
> unsigned int *loadtga(char *filename, int size) {
> unsigned char r,g,b;
> int i=0;
> FILE *fd;
> unsigned int *p;
> fd=fopen(filename,"rb");
> printf("%d\n",fd);
> fflush(stdout);
> if(!fd) { printf("couldn't open file %s!\n",filename); exit(0); }
> fseek(fd,18,SEEK_SET);
> p=calloc(size,sizeof(int));
> if(!p) { printf("calloc failed in loadtga!\n"); exit(0); }
> while(!feof(fd) || i<size) {
If the file has more than `size' triples, you'll overrun the p array
here. This could easily cause crashes in free and the like (fclose
calls free internally). You probably want
while (!feof(fd) && i<size)
> b=fgetc(fd);
> g=fgetc(fd);
> r=fgetc(fd);
> p[i++]=(r<<16)+(g<<8)+b;
> }
> printf("%d\n",fd);
> fflush(stdout);
> fclose(fd);
> return p;
> }
>
> int main(...) {
>
> backg=loadtga("backgrnd.tga",640*480);
>
> while(!kbhit()) {
> ...
> }
>
> free(backg);
>
> }
>
> What is wrong??
>
> ps.
> please try to answer as email atleast! I don't read this newgroup that
> often!
>
> - Scorpion - scorpion AT sgic DOT fi - www.sgic.fi/~scorpion -
> -------------------------------------------------------
> Experience is something what you can't get until just
> after you need it.
> -------------------------------------------------------
--
Nate Eldredge
neldredge AT hmc DOT edu
- Raw text -