Thread bringt Programm zum Absturz
-
Jetzt steige ich garnichtmehr durch...
Wenn ich eine Variable oben also unter die includes und so schreibe, dann ist sie doch Global oder?
Wann soll ich wo new machen?
Ich habe schon danach gesucht wie ich den struct zu einem Member der klasse mache..... doch verstehen wie ich es machen muss tue ich nicht....
Ich bin gerade echt am verzweifeln.... hier nochmals mein code... vieleicht ist ja einer so net und zeigt mir wie ich es richtig machen muss...
InFaIN
//***************// //Theard bringt programm zum absturz #pragma once #pragma comment(lib, "DevIL.lib") #pragma comment(lib, "ILU.lib") #include "IL\il.h" #include "IL\ilu.h" #include <string> #include <vcclr.h> #include "windows.h" using namespace std; string a_pfad = ""; struct s_scale { char* in; char* out; int size; }; s_scale struct_s; namespace Bildload_alpha_1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Zusammenfassung für Form1 /// /// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch /// die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern, /// das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt. /// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen /// arbeiten, die diesem Formular zugewiesen sind. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Konstruktorcode hier hinzufügen. // //Init IL ilInit(); iluInit(); } protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::PictureBox^ c_vorschau; private: System::Windows::Forms::MenuStrip^ c_menu; protected: private: System::Windows::Forms::ProgressBar^ c_status_bar; private: System::Windows::Forms::Button^ c_upload; private: System::Windows::Forms::TextBox^ c_pfad; private: System::Windows::Forms::Button^ c_offnen; private: System::Windows::Forms::OpenFileDialog^ c_openFile; protected: protected: private: /// <summary> /// Erforderliche Designervariable. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { this->c_vorschau = (gcnew System::Windows::Forms::PictureBox()); this->c_menu = (gcnew System::Windows::Forms::MenuStrip()); this->c_status_bar = (gcnew System::Windows::Forms::ProgressBar()); this->c_upload = (gcnew System::Windows::Forms::Button()); this->c_pfad = (gcnew System::Windows::Forms::TextBox()); this->c_offnen = (gcnew System::Windows::Forms::Button()); this->c_openFile = (gcnew System::Windows::Forms::OpenFileDialog()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->c_vorschau))->BeginInit(); this->SuspendLayout(); // // c_vorschau // this->c_vorschau->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle; this->c_vorschau->Location = System::Drawing::Point(12, 27); this->c_vorschau->Name = L"c_vorschau"; this->c_vorschau->Size = System::Drawing::Size(300, 300); this->c_vorschau->TabIndex = 0; this->c_vorschau->TabStop = false; // // c_menu // this->c_menu->Location = System::Drawing::Point(0, 0); this->c_menu->Name = L"c_menu"; this->c_menu->RenderMode = System::Windows::Forms::ToolStripRenderMode::System; this->c_menu->Size = System::Drawing::Size(324, 24); this->c_menu->TabIndex = 1; this->c_menu->Text = L"menuStrip1"; // // c_status_bar // this->c_status_bar->Location = System::Drawing::Point(12, 334); this->c_status_bar->MarqueeAnimationSpeed = 30; this->c_status_bar->Name = L"c_status_bar"; this->c_status_bar->Size = System::Drawing::Size(300, 17); this->c_status_bar->TabIndex = 2; // // c_upload // this->c_upload->Location = System::Drawing::Point(123, 357); this->c_upload->Name = L"c_upload"; this->c_upload->Size = System::Drawing::Size(75, 23); this->c_upload->TabIndex = 3; this->c_upload->Text = L"Upload"; this->c_upload->UseVisualStyleBackColor = true; // // c_pfad // this->c_pfad->Location = System::Drawing::Point(12, 386); this->c_pfad->Name = L"c_pfad"; this->c_pfad->Size = System::Drawing::Size(256, 20); this->c_pfad->TabIndex = 4; // // c_offnen // this->c_offnen->Location = System::Drawing::Point(274, 382); this->c_offnen->Name = L"c_offnen"; this->c_offnen->Size = System::Drawing::Size(37, 23); this->c_offnen->TabIndex = 5; this->c_offnen->Text = L"..."; this->c_offnen->UseVisualStyleBackColor = true; this->c_offnen->Click += gcnew System::EventHandler(this, &Form1::c_offnen_Click); // // c_openFile // this->c_openFile->Filter = L"All (*.*)|*.*|Jpeg (*.jpg)|*.jpg|Photoshop (*.psd)|*.psd"; this->c_openFile->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::c_openFile_FileOk); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(324, 414); this->Controls->Add(this->c_offnen); this->Controls->Add(this->c_pfad); this->Controls->Add(this->c_upload); this->Controls->Add(this->c_status_bar); this->Controls->Add(this->c_vorschau); this->Controls->Add(this->c_menu); this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; this->MaximizeBox = false; this->Name = L"Form1"; this->Text = L"Bildload alpha v1"; (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->c_vorschau))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void c_offnen_Click(System::Object^ sender, System::EventArgs^ e) { //this->c_status_bar->Style = System::Windows::Forms::ProgressBarStyle::Marquee; c_openFile->ShowDialog(); } private: System::Void c_openFile_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) { //this->c_status_bar->Style = System::Windows::Forms::ProgressBarStyle::Blocks; c_pfad->Text = c_openFile->FileName; a_pfad = strtochar(c_openFile->FileName); struct_s.in = strtochar(c_openFile->FileName); struct_s.out = "tmp_v.jpg"; struct_s.size = 300; //scale_img(struct_s); HANDLE hThread1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)scale_img, (LPVOID)&struct_s, 0, 0); } //***** scale_img() || Scaliert das Bild auf die maximale breite oder höhe. *****// static long WINAPI scale_img(LPVOID param) { s_scale *scale=(s_scale*)param; char* in; char* out; int max; in = scale->in; out = scale->out; max = scale->size; bool err = ilLoadImage(in); iluImageParameter(ILU_FILTER, ILU_SCALE_BSPLINE); int img_height = ilGetInteger(IL_IMAGE_HEIGHT); int img_width = ilGetInteger(IL_IMAGE_WIDTH); if(img_height > max && img_width > max){ if(img_height > img_width){ int scale = (img_width * max)/img_height; iluScale(scale,max,32); }else{ int scale = (img_height * max)/img_width; iluScale(max,scale,32); }} bool err2 = ilSaveImage(out); return 0; } //***** strtochar() || Wandelt einen System::String^ in ein char* um *****// public: char* strtochar(String ^str) { pin_ptr<const wchar_t> wch = PtrToStringChars(str); size_t convertedChars = 0; size_t sizeInBytes = ((str->Length + 1) * 2); errno_t err = 0; char *ch = (char *)malloc(sizeInBytes); err = wcstombs_s(&convertedChars, ch, sizeInBytes,wch, sizeInBytes); return ch; } }; }
-
Das ist ja "global"... dann ist es ok, sorry..
-
Aber es funktioniert trozdem nicht
Genau das verwundert mich ja weil es ist ja global.....
InFaIN
-
Hat keiner mehr eine Idee?
Ist das jetzt eigentlich ein verbotenes Theardpushing? Oder geht das ok wenn nach 2 Tagen keiner Antwortet?
InFaIN
-
Weiss nicht, aber ich glaube es interessiert einfach keinen mehr.
Du machst es einem halt schwer dir helfen zu wollen.Wenn du auch beim 1000sten mal noch immer nicht selbst dazuschreibst WAS denn genau passiert interessierts halt keinen mehr zu raten oder zu fragen.
Und dein Code ist einfach grausam. Sieht halt verdächtig aus nach "ich hab überhaupt keine Ahnung, copy/paste mir Code zusammen, und frag dann im Forum bis es mir einer richtet".
Blub.
Geh hin und lern dir selbst zu helfen.
-
Harte Worte, aber was Wahres ist schon dran, ehrlich gesagt. Ich hätte erwartet, dass eine sinnvollere Fehlerbeschreibung als "Aber es funktioniert trozdem nicht" kommt. Denn ein Zeiger auf einen ungültigen Speicherbereich kann es ja jetzt nicht mehr sein. Mein Rat: freunde dich mit dem Debugger an! Geh schrittweise durch und lokalisiere das Problem. Breakpoints funktionieren schließlich auch in Threadfunktionen, also setze sie ein...
Und arbeite an deiner Code-Formatierung...