• Image causing my form to crash
    14 replies, posted
For the past 2 weeks I have been bored as hell. So I just started making an OS. But when ever I tell it to load a custom image for the wallpaper using: [code] // Settings string IMAGE; OpenFileDialog Image = new OpenFileDialog(); Image.Filter = "*.jpg (*.Jpg)| *.Jpg"; if(Image.ShowDialog()==DialogResult.OK) { try { IMAGE = Image.FileName(); File.WriteAllText("Wallpaper.txt", Image.FileName); } catch { } } -------------------------------------------- // main private void Form1_Load(object sender, EventArgs e) { try { this.BackgroundImage = Image.FromFile(File.ReadAllText("Wallpaper.txt"); } catch { } } [/code] The Form just freezes, sucks up all me memory, then it crashes with some memory exception. And it's really pissing me off. P.S: Sorry if the title has some spelling errors, I was in a rush when I posted this.
[QUOTE=wilderbeast;20332733]For the past 2 weeks I have been bored as hell. So I just started making an OS. But when ever I tell it to load a custom image for the wallpaper using: The Form just freezes, sucks up all me memory, then it crashes with some memory exception. And it's really pissing me off. P.S: Sorry if the title has some spelling errors, I was in a rush when I posted this.[/QUOTE] I think you are missing a ')' [code] Image.Filter = "*.jpg (*.Jpg)| *.Jpg"[B])[/B]; [/code]
[QUOTE=Wipmuck;20334212]I think you are missing a ')' [code] Image.Filter = "*.jpg (*.Jpg)| *.Jpg"[B])[/B]; [/code][/QUOTE] That'd be picked up at compile time. There's no syntax error there.
Step through it in the debugger and find out which line causes the problem.
The only place I could see there being an error is in your 'Wallpaper.txt' file. If you open it with notepad, does it have a carriage return at the end? ie you can place your cursor on the second line WITHOUT adding an enter.
[QUOTE=Mattz333;20345298]The only place I could see there being an error is in your 'Wallpaper.txt' file. If you open it with notepad, does it have a carriage return at the end? ie you can place your cursor on the second line WITHOUT adding an enter.[/QUOTE] It's working like a normal notepad file. Press enter goes to the next line. Normal, or is there somthing fu#ked up here?
That's not an OS bro.
[QUOTE=turb_;20395601]That's not an OS bro.[/QUOTE] Was wondering how long it would take for someone to post this :v:
Does it crash on the reading or writing?
[QUOTE=Agent766;20396505]Does it crash on the reading or writing?[/QUOTE] Reading. [editline]05:15PM[/editline] [QUOTE=turb_;20395601]That's not an OS bro.[/QUOTE] Have you ever heard of the word 'Virtual'? I don't have the skills to make one from scratch. I just use a virtual machine to overlay windows. It runs like an os, but uses windows instead of a kernal.
[QUOTE=wilderbeast;20399067]Have you ever heard of the word 'Virtual'? I don't have the skills to make one from scratch. I just use a virtual machine to overlay windows. It runs like an os, but uses windows instead of a kernal.[/QUOTE] Yeah, I do know the word virtual - I use VMs to test my own bootable kernels. But that doesn't change the fact that your 'OS' is not an Operating System, it is a shell.
Why are you explicitly swallowing all exceptions? You should really learn them properly. (You might even *gasp* find out what went wrong in your code!)
[QUOTE=turb_;20411117]Yeah, I do know the word virtual - I use VMs to test my own bootable kernels. But that doesn't change the fact that your 'OS' is not an Operating System, it is a shell.[/QUOTE] You could've used this post to help, but instead you choose to nitpick.
[QUOTE=wilderbeast;20332733]For the past 2 weeks I have been bored as hell. So I just started making an OS. But when ever I tell it to load a custom image for the wallpaper using: [code] // Settings string IMAGE; OpenFileDialog Image = new OpenFileDialog(); Image.Filter = "*.jpg (*.Jpg)| *.Jpg"; if(Image.ShowDialog()==DialogResult.OK) { try { IMAGE = Image.FileName(); File.WriteAllText("Wallpaper.txt", Image.FileName); } catch { } } -------------------------------------------- // main private void Form1_Load(object sender, EventArgs e) { try { this.BackgroundImage = Image.FromFile(File.ReadAllText("Wallpaper.txt"); } catch { } } [/code] The Form just freezes, sucks up all me memory, then it crashes with some memory exception. And it's really pissing me off. P.S: Sorry if the title has some spelling errors, I was in a rush when I posted this.[/QUOTE] Like jA_cOp said, you shouldn't have empty catch statements in all your code. But, the fact that your program is crashing instead of continuing seems to imply the crash is happening elsewhere. Although your code is could probably be causing it somehow. In any case, you should flesh out the catch statements with an exception argument and actually handle the exceptions. [QUOTE=UberMensch;20414685]You could've used this post to help, but instead you choose to nitpick.[/QUOTE] Welcome to the programming forum. May I take your coat?
[QUOTE=UberMensch;20414685]You could've used this post to help, but instead you choose to nitpick.[/QUOTE] Nitpicking? A shell is a tiny component of an Operating System.
Sorry, you need to Log In to post a reply to this thread.