Programm hängt sich bei Variablenzugriff auf
-
Hallo !
Ich bin gerade dabei eine DLL (Plugin) für Weaverslave zu schreiben.
Dummerweise hängt sich mein Code beim Zugriff auf eine Variable auf...
Es gibt keine Fehlermeldung. Die Codeausführung bleibt einfach stehen und das Programm (Weaverslave) verbraucht nahezu 100% Prozessorleistung (endlosschleife oder so). (Muss am Weaverslavecode liegen)Es handelt sich bei der Variable um
char dateiName[MAX_PATH];.
Sie ist Bestandteil der Klasse Defiant_Node(=BaumstrukturKnoten) (in Start cl_Tree) die von einem Thread rekursiv gefüllt wird.
Das ganze läuft folgendermaßen:
Defiantklasse beinhaltetDefiant_Node* cl_Tree;.
Ruft in Defiant::Start einen Thread auf und übergibt cl_Tree.
Anschließend wird die Nachrichtenschleife eines Fensters gestartet.Der Thread füllt cl_Tree.
Schließt das Fenster / Beendet die Nachrichtenschleife.
Beendet sich selbst.Defiant::Start verwendet den gefüllten Baum cl_Tree weiter.
Hängt sich auf.Woran liegt es, dass sich ein Programm beim Zugriff auf eine Variable aufhängt?
Muss ich beim Benutzen von Threads noch weiteres beachten, obwohl hier keine Überlagerungen auftreten (sollten)?unsigned __stdcall def_WorkingThread(void* pParam) { Defiant_Thread_Parameter* param; param = (Defiant_Thread_Parameter*) pParam; Defiant::wt_GatherFiles(param->df_locs,param->Pfad,param->Name); char* targetFile = new char[MAX_PATH]; targetFile = strcat(strdup(param->Pfad), strdup(param->Name)); MessageBox(NULL,targetFile,"TargetFile start",0); param->df_node = new Defiant_Node(targetFile,param->Name,param->df_locs); // abhängigen-Strang gefüllt SendMessage(param->hWnd,WM_CLOSE,NULL,NULL); // progress-Fenster schließen // weiteres siehe Defiant::Start return 0; } // [...] void Defiant::Start(char* FilePos,int len,HINSTANCE hInstance) { ProjektPath = new char[len]; ProjektName = new char[len]; strcpy(ProjektName,FilePos); ProjektName = GetFileName(FilePos,len); ProjektPath = GetFilePath(FilePos,len); // ProjektPath beinhaltet nun den Pfad (mit \ hinten) // parameter "speichern" //cl_Locations.Add(ProjektPath,ProjektName); // Fensteroberfläche laden... Progress_Window pro_Fenster; pro_Fenster.Show_Pro_Window(hInstance); // WorkerThread starten... int thread_id=0; unsigned ti1; thread_parameter.Pfad = ProjektPath; thread_parameter.Name = ProjektName; thread_parameter.hWnd = pro_Fenster.hWnd; thread_parameter.df_locs = &cl_Locations; thread_parameter.df_node = cl_Tree; Defiant::SetStatus(pro_Fenster.hWnd,0,pro_Init,NULL); _beginthreadex(0, 0, def_WorkingThread, (void*)&thread_parameter, 0, &ti1 ); // MessageLoop betreten... pro_Fenster.Enter_Message_Loop(hInstance); // Fenster geschlossen (durch den thread) // Schleife beendet // resultfenster+hwnds vorbereiten Result_Window res_Fenster; res_Fenster.Show_Res_Window(hInstance); // hwnds gefüllt HWND Tview; Tview = res_Fenster.hTree; MessageBox(NULL,"<<<<<test>>>>>>>>>","",0); // nach dem klick auf ok hängt sich das programm auf cl_Tree->FillTV(Tview,NULL); MessageBox(NULL,"filling ended","",0); res_Fenster.Enter_Message_Loop(hInstance); } // [...] Defiant_Node::FillTV(HWND Tview,HTREEITEM base) { MessageBox(NULL,dateiName,"",0); } // [...] class Defiant_Node { public: FillTV(HWND,HTREEITEM); Defiant_Node(char*,char*,Defiant_Locations*); Defiant_Node(); static HTREEITEM AddItemToTree(HWND, LPSTR, HTREEITEM, HTREEITEM); virtual ~Defiant_Node(); char dateiName[MAX_PATH]; deque<Defiant_Node*> links; private: int links_count; HTREEITEM tv_Item; Parse(Defiant_Locations*); char dateiLocation[MAX_PATH]; char* tmp_Buffer; DWORD datei_size; HANDLE datei; }; Defiant_Node::Defiant_Node(char *TargetFile,char* TargetFileName,Defiant_Locations* locs) { links_count = 0; //targetfile = gesamter dateipfad+name //targetfilename = nur name char statBuffer[MAX_PATH+sizeof(pro_Read_)]; strcpy(dateiLocation,TargetFile); strcpy(dateiName,TargetFileName); // lokale kopie muss angefertigt werden ! datei = CreateFile( dateiLocation, // pointer to name of the file GENERIC_READ, // access (read-write) mode FILE_SHARE_READ, // share mode NULL,// pointer to security attributes OPEN_EXISTING, // how to create NULL, // file attributes NULL // handle to file with attributes to // copy ); datei_size = GetFileSize(datei,NULL); strcpy(statBuffer,pro_Read_); strcat(statBuffer,dateiLocation); Defiant::SetStatus(NULL,0,statBuffer,datei_size); // status : Reading blblblabalba tmp_Buffer = new char[datei_size]; if(tmp_Buffer == NULL) MessageBox(NULL,pro_Read_Mem_Error,gen_Error,MB_OK | MB_ICONERROR); ULONG read=0; ReadFile( datei, // handle of file to read tmp_Buffer, // pointer to buffer that receives data datei_size, // number of bytes to read &read, // pointer to number of bytes read NULL // pointer to structure for data ); // tmp_Buffer ist mit der Datei gefüllt... //Parsen wenn erfolgreich if(tmp_Buffer != NULL) Parse(locs); else Defiant::SetStatus(NULL,0,pro_Read_noread,NULL); } Defiant_Node::Parse(Defiant_Locations* locs) { tmp_Buffer = strupr(tmp_Buffer); // uppercase Defiant::SetStatus(NULL,0,NULL,locs->GetSize()); for(int i=0;i<locs->GetSize();i++) { //MessageBox(NULL,"parsing",locs->GetItem(i)->loc_Filename,0); if(strstr(tmp_Buffer,locs->GetItem(i)->loc_Filename)!=NULL) { // dateiname wurde gefunden // pfad\datei vorbereiten char* pfad_Datei = new char[MAX_PATH]; pfad_Datei = strcat(locs->GetItem(i)->loc_Path, locs->GetItem(i)->loc_Filename); if(strcmp(pfad_Datei, dateiLocation) != 0){ // dateinamen (!) miteinander vergleichen char* buf; Defiant_Locations* pointer; buf = strdup(locs->GetItem(i)->loc_Filename); pointer = locs->Delete(i); if(pointer != NULL) locs = pointer; //MessageBox(NULL,locs->GetItem(2)->loc_Filename,locs->GetItem(3)->loc_Filename,0); links.push_back( new Defiant_Node(pfad_Datei, buf, locs) ); links_count++; // sich nicht selbst aufrufen // TODO: das alte "eigene" locationding löschen spätestens // jetzt löschen (vor new natürlich) } delete pfad_Datei; } Defiant::SetStatus(NULL,i,NULL,NULL); } }Viel Code
aber vielen Dank an jeden, der sich gedanklich mit meinem Problem beschäftigt 
-
ja hehehe

cl_Tree = thread_parameter.df_node;Eine Zeile
Enorm viel Wirkung...