Thread overview | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 29, 2008 dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Recently I read a DWT example ,a simple window form contains a label which has a gif image.when form resize,the label either show the whole picture or a messagebox hints the form is too small which can not show the whole image.When I comile the source,an Exception was thrown with info" Array Index out of bounds.",I have no clue about this exception message.Who can help? Thanks. //******************************* // smile.gif is in the same folder with source file module resizeapp; import dwt.DWT; import dwt.widgets.Display; import dwt.widgets.Shell; import dwt.widgets.Label; import dwt.graphics.Image; import dwt.graphics.ImageData; import dwt.layout.GridLayout; import dwt.layout.GridData; import dwt.events.ControlAdapter; import dwt.events.ControlEvent; import dwt.widgets.MessageBox; import tango.core.Exception; class MainForm { private: Display display; Shell shell; Label label; Image image; void InitializeComponents() { display=new Display; shell =new Shell(display); image=new Image(display,r"smile.gif"); shell.setLayout(new GridLayout); label=new Label(shell,DWT.NONE); label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); label.setImage(image); shell.setData(label); shell.addControlListener(new class ControlAdapter{ public void controlResized(ControlEvent e) { Shell shell=cast(Shell)e.getSource; Label label=cast(Label)shell.getData; Rectangle rect=shell.getClientArea; ImageData data=label.getImage.getImageData; if(rect.width<data.width || rect.height<data.height) { shell.setText("Too small"); label.setText("Oh~ No"); } else { shell.setText("Smile everyday!"); label.setImage(label.getImage); } } }); shell.pack; shell.open; while(! shell.isDisposed) { if(! display.readAndDispatch) display.sleep; } if(!(image is null)) image.dispose; display.dispose; } public: this() { InitializeComponents; } } int main(char[][] args) { try { MainForm mainForm=new MainForm; } catch(Exception e) { MessageBox.showError(e.toString,"Fatal Error"); return -1; } return 0; } //***************************************** |
August 29, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | To compile your example the line import dwt.graphics.Rectangle; was missing. The array bounds exception was a bug in DWT. It is fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 Thanks for your interest in DWT and reporting this problem. Frank |
August 29, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Hi Frank, I am realy impressed by this site's prompt response to however stupid questions raised by some newbies just like me,Thanks! Should I download the new updated Image.d file and overwrite the old one in dwt ?If this is true,then the sam problem:It still can not work with the exact same exception:Array Index out of bounds. P.S.:I have added the import import dwt.graphics.Rectangle. |
August 29, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | Sam Hu schrieb: > Hi Frank, > > I am realy impressed by this site's prompt response to however stupid questions raised by some newbies just like me,Thanks! > > Should I download the new updated Image.d file and overwrite the old one in dwt ?If this is true,then the sam problem:It still can not work with the exact same exception:Array Index out of bounds. > P.S.:I have added the import import dwt.graphics.Rectangle. If you have downloaded the release, you can now download the latest version of dwt-win here: http://hg.dsource.org/projects/dwt-win/archive/tip.zip (alternatively you could use mercurial directly) If you use DSSS to build your application, you can pass the "-full -debug -g" option. If you still have the same problem, .. hm. I used the GIF from dwt-addons/res/region_shell.gif to produce the error. Does this work? With DDBG from http://ddbg.mainia.de/ you can run the program and get a stacktrace to show the possition of the crash. Therefor remove the try/catch in you main function and start the program like this: ddbg test.exe then type 'r<enter' to start the program. When the crash occurs the debugger stopps, type 'us<enter>' to get the stacktrace. Frank |
August 29, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit Attachments: | Hi Frank, Sorry ,the same problem. 1.Not using try...catch block when I run the compiled program from cmd line,exception message is as below: tango.core.exception.ArrayBoundsException@dwt.graphics.Image(715):Array index out of bounds 2.Following your instruction to debug by ddbg,please refer to the attached screen shot. Thanks. Sam |
August 30, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | Sam The stacktrace is informative and shows that your example crashes in another place than i found a problem. Unfortunately i cannot reproduce the problem. Can you post your 'smile.gif'? Or does that also happen for you when you use one of the gif files from the dwt-samples/res folder? Which OS are you running? WinXP 32 bit? How exactly do you build your application? Do you build all directly or using dwt libs? I found a comment, about a crash in exactly the line your stacktrace points to: Image.d line 679. See line 605 /* * Bug in GDI+. For some reason, Bitmap.LockBits() segment faults * when loading GIF files in 64-bit Windows. The fix is to not use * GDI+ image loading in this case. */ if (gdip && (void*).sizeof is 8 && filename.toLowerCase().endsWith(".gif")) gdip = false; Does this apply to your machine? Frank |
September 01, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit Attachments: | This time I use another gif image file located in dwt-samples\res and then I can pass the compile also.When I run the program,it crashed also with the same message.Below is the resoure and the attached please found the compile information and the exception message when I run the program. //********************************************** module resizeapp; import dwt.DWT; import dwt.widgets.Display; import dwt.widgets.Shell; import dwt.widgets.Label; import dwt.graphics.Image; import dwt.graphics.ImageData; import dwt.graphics.Rectangle; import dwt.layout.GridLayout; import dwt.layout.GridData; import dwt.events.ControlAdapter; import dwt.events.ControlEvent; import dwt.widgets.MessageBox; import tango.core.Exception; class MainForm { private: Display display; Shell shell; Label label; Image image; void InitializeComponents() { display=new Display; shell =new Shell(display); image=new Image(display,r"c:\bigd\dwt-samples\res\region_shell.gif"); shell.setLayout(new GridLayout); label=new Label(shell,DWT.NONE); label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); label.setImage(image); shell.setData(label); shell.addControlListener(new class ControlAdapter{ public void controlResized(ControlEvent e) { Shell shell=cast(Shell)e.getSource; Label label=cast(Label)shell.getData; Rectangle rect=shell.getClientArea; ImageData data=label.getImage.getImageData; if(rect.width<data.width || rect.height<data.height) { shell.setText("Too small"); label.setText("I'm melting"); } else { shell.setText("Happy Guy Fits"); label.setImage(label.getImage); } } }); shell.pack; shell.open; while(! shell.isDisposed) { if(! display.readAndDispatch) display.sleep; } if(!(image is null)) image.dispose; display.dispose; } public: this() { InitializeComponents; } } int main(char[][] args) { try { MainForm mainForm=new MainForm; } catch(Exception e) { MessageBox.showError(e.toString,"Fatal Error"); return -1; } return 0; } //********************************************** Thanks, Sam |
September 01, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | this code works for me. I will install SP3 to see if i can reproduce the problem. |
September 01, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | On Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton@googlemail.com> wrote:
> this code works for me.
> I will install SP3 to see if i can reproduce the problem.
I have the same bug, too. Windows 2003 Server
|
September 01, 2008 Re: dwt learning question,please help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden@gmail.com> wrote: > On Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton@googlemail.com> wrote: > >> this code works for me. >> I will install SP3 to see if i can reproduce the problem. > > I have the same bug, too. Windows 2003 Server More info: Tango backtrace hack intiated Unhandled D exception! Error: Array index out of bounds (tango.core.Exception.ArrayBoundsException) in dwt.graphics.Image [715] backtrace: 004d5d51 onArrayBoundsError (+25) 00404087 void resizeapp.MainForm.InitializeComponents(void*) (+67) resizeapp.d:32 00404290 class resizeapp.MainForm resizeapp.MainForm._ctor(void*)А (+10) resizeapp.d:79 004042ab _Dmain (+17) resizeapp.d:86 004d3041 extern (C) int dmain2.main(int, char**) . void runMain(void*) (+d) 004df062 mainCRTStartup (+aa) 77e6f23c ??? 00000001 ??? 712 RGB[] rgbs = new RGB[colorPalette.Count]; 713 paletteData = new PaletteData(rgbs); 714 for (int i = 0; i < colorPalette.Count; i++) { 715 if (((palette.Entries[i] >> 24) & 0xFF) is 0 && (colorPalette.Flags & Gdip.PaletteFlagsHasAlpha) !is 0) { 716 transparentPixel = i; 717 } 718 rgbs[i] = new RGB(((palette.Entries[i] & 0xFF0000) >> 16), ((palette.Entries[i] & 0xFF00) >> 8), ((palette.Entries[i] & 0xFF) >> 0)); 719 } 720 OS.HeapFree(hHeap, 0, palette); 721 break; |
Copyright © 1999-2021 by the D Language Foundation