Hello. Such a problem arose, I decided to build a release version for the test. And 5-6 out of 10 times when this code is executed (reading from a file) a crash occurs: The pile was damaged (parameters: 0x776D4270). When debugging, the error points to these lines.

HANIM::HANIM(char *_name) { wight=0; height=0; numframes=0; name=_name; f=fopen(name, "rb"); if (f == NULL) { exit(1); } fread( &numframes, sizeof(int),1 , f );//кадры fread( &wight, sizeof(int),1 , f );//ширина fread( &height, sizeof(int),1 , f );//высота 

An error occurs on the fread command. What can be done?

  class HANIM { public: HANIM(char *name); ~HANIM(); char *name; //HTEXTURE tex[100];//больше не используется int wight; int height; int numframes; protected: FILE *f; }; 

Program 1 creates a file and writes information there. First, we write initial information to the file.

 fwrite(&frames,sizeof(int),1,f); fwrite(&wight,sizeof(int),1,f); fwrite(&height,sizeof(int),1,f); 

Next, we write the data packet packed through zlib.

  for( unsigned int i=0;i<destLen;i++) { fwrite(&packt[i],sizeof(int),1,f); }; 

Then, another program sequentially, in the same order, retrieves information.

All file uploader code

 #ifndef DSANIM_H #define DSANIM_H #include <hge.h>-графический двиг #include <hgesprite.h>-графический двиг #include <fstream> #include <iostream> #include <vector> #include "zlib.h" extern HGE *hge; using namespace std; class HANIM { public: HANIM(char *name); ~HANIM(); char *name; int wight; int height; int numframes; vector<HTEXTURE> tex;//созданные текстуры protected: FILE *f; DWORD *val; DWORD tz; DWORD a; DWORD red; DWORD green; DWORD blue; int loadmode; DWORD testmass; unsigned long destLen; unsigned long compLen; }; #endif #include "dsanim.h" HANIM::HANIM(char *_name) { loadmode=2; wight=0; height=0; numframes=0; name=_name; f=fopen(name, "rb"); if (f == NULL) { hge->System_Log("Файл повреждён :%s", name); exit(1); } int y=0; fread( &numframes, sizeof(int),1 , f );//кадры fread( &wight, sizeof(int),1 , f );//ширина fread( &height, sizeof(int),1 , f );//высота /*for(int i=1;i<numframes;i++) { tex[i] = hge->Texture_Create(wight,height); };*/ if(loadmode==1) {//не используется }; if(loadmode==2)//сжатые файлы { unsigned long ff; ff=0; unsigned long d1; unsigned long d2; fread(&d1, sizeof(unsigned long), 1, f);//несжат fread(&d2, sizeof(unsigned long), 1, f);//сжат unsigned char *newmass=new unsigned char[d2];//несжат unsigned char *newmassu=new unsigned char[d1];//сжат for( unsigned int i=0;i<d2;i++) { fread( &newmass[i], sizeof(int),1 , f );//сжатые данные }; if (Z_OK == uncompress(newmassu, &d1, newmass, d2)) { for (int fr = 0; fr < numframes; fr++) { tex.push_back(hge->Texture_Create(wight, height)); hgeU32 *pixels = hge->Texture_Lock(tex.at(fr), false); for (int i = 0; i < (wight*height); i++) { pixels[i] = ARGB(newmassu[ff + 3], newmassu[ff + 2], newmassu[ff + 1], newmassu[ff]); ff = ff + 4; }; hge->Texture_Unlock(tex.at(fr)); }; }; newmass=0; newmassu=0; }; fclose(f); }; HANIM::~HANIM() { }; 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin

0