digitalmars.D.dwt - dwt learning question,please help
- Sam Hu (83/83) Aug 28 2008 Recently I read a DWT example ,a simple window form contains a label whi...
- Frank Benoit (7/7) Aug 28 2008 To compile your example the line
- Sam Hu (4/4) Aug 28 2008 Hi Frank,
- Frank Benoit (18/24) Aug 29 2008 If you have downloaded the release, you can now download the latest
- Sam Hu (8/8) Aug 29 2008 Hi Frank,
- Frank Benoit (20/20) Aug 30 2008 Sam
- Sam Hu (88/88) Aug 31 2008 This time I use another gif image file located in dwt-samples\res and th...
- Frank Benoit (2/2) Sep 01 2008 this code works for me.
- Denis Koroskin (3/5) Sep 01 2008 I have the same bug, too. Windows 2003 Server
- Denis Koroskin (31/36) Sep 01 2008 More info:
- Frank Benoit (6/48) Sep 01 2008 This was fixed in
- Denis Koroskin (5/55) Sep 01 2008 Ouch! Are you sure this fixes the issue and not hides it? It's quite cle...
- Frank Benoit (15/76) Sep 01 2008 you mean
- Denis Koroskin (4/82) Sep 02 2008 Yes, that was a typo.
- Sam Hu (4/4) Sep 04 2008 Hi Frank,
- Frank Benoit (8/14) Sep 04 2008 Sam Hu
- Denis Koroskin (9/69) Sep 08 2008 This one still prevents me from sleepping :)
- Frank Benoit (3/13) Sep 08 2008 Hehe. This seems to me exactly the same code?
- Frank Benoit (2/4) Sep 01 2008 Works also with SP3 on my WinXp
- Sam Hu (4/4) Aug 31 2008 Frank,
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; } //*****************************************
Aug 28 2008
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
Aug 28 2008
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.
Aug 28 2008
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
Aug 29 2008
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
Aug 29 2008
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
Aug 30 2008
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
Aug 31 2008
this code works for me. I will install SP3 to see if i can reproduce the problem.
Sep 01 2008
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
Sep 01 2008
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: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;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
Sep 01 2008
Denis Koroskin Wrote:On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden gmail.com> wrote:This was fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 can you please retry with the newest tip version? http://hg.dsource.org/projects/dwt-win/archive/tip.zip FrankOn Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton googlemail.com> wrote: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;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
Sep 01 2008
On Mon, 01 Sep 2008 16:21:12 +0400, Frank Benoit <keinfarbton googlemail.com> wrote:Denis Koroskin Wrote:Ouch! Are you sure this fixes the issue and not hides it? It's quite clear that the bug is somewhere else, colorPalette.Count == palette.Entries should always evaluate to true.On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden gmail.com> wrote:This was fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 can you please retry with the newest tip version? http://hg.dsource.org/projects/dwt-win/archive/tip.zip FrankOn Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton googlemail.com> wrote: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;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
Sep 01 2008
Denis Koroskin schrieb:On Mon, 01 Sep 2008 16:21:12 +0400, Frank Benoit <keinfarbton googlemail.com> wrote:you mean colorPalette.Count == palette.Entries.length ? I think this is not true. It would be true if Entries would be an dynamic array. But it is static array, hence the length is always 1. But the real array /can/ be longer. struct ColorPalette { int Flags; int Count; int[1] Entries; } To avoid the array bounds check i changed the code to use the pointer arithmetic. Does that make sense?Denis Koroskin Wrote:Ouch! Are you sure this fixes the issue and not hides it? It's quite clear that the bug is somewhere else, colorPalette.Count == palette.Entries should always evaluate to true.On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden gmail.com> wrote:This was fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 can you please retry with the newest tip version? http://hg.dsource.org/projects/dwt-win/archive/tip.zip FrankOn Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton googlemail.com> wrote: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;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
Sep 01 2008
On Tue, 02 Sep 2008 02:24:20 +0400, Frank Benoit <keinfarbton googlemail.com> wrote:Denis Koroskin schrieb:Yes, that was a typo.On Mon, 01 Sep 2008 16:21:12 +0400, Frank Benoit <keinfarbton googlemail.com> wrote:you mean colorPalette.Count == palette.Entries.length ?Denis Koroskin Wrote:Ouch! Are you sure this fixes the issue and not hides it? It's quite clear that the bug is somewhere else, colorPalette.Count == palette.Entries should always evaluate to true.On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden gmail.com> wrote:This was fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 can you please retry with the newest tip version? http://hg.dsource.org/projects/dwt-win/archive/tip.zip FrankOn Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton googlemail.com> wrote: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;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 ServerI think this is not true. It would be true if Entries would be an dynamic array. But it is static array, hence the length is always 1. But the real array /can/ be longer. struct ColorPalette { int Flags; int Count; int[1] Entries; } To avoid the array bounds check i changed the code to use the pointer arithmetic. Does that make sense?Ah, now yes. Thank you for explanation!
Sep 02 2008
Hi Frank, I tried the same code in Jave(of course it need some slight change) it works fine while it is an Array bounds out of index exception in D. Regards, Sam
Sep 04 2008
Sam Hu schrieb:Hi Frank, I tried the same code in Jave(of course it need some slight change) it works fine while it is an Array bounds out of index exception in D. Regards, SamSam Hu I fixed one problem with array bounds exception. After that i could never reproduce the problem you have. Perhaps someone else will report the same problem with another hint how to reproduce. Can you use a PNG as a workaround? Frank
Sep 04 2008
Hi Frank, When I change to a png image,it works and it seems everything is fine! So what can I learn from it? Thanks, Sam
Sep 07 2008
Hi Frank, When I change to a png image,it works and it seems everything is fine! So what can I learn from it? Thanks, Sam
Sep 07 2008
On Tue, 02 Sep 2008 01:50:49 +0400, Denis Koroskin <2korden gmail.com> wrote:On Mon, 01 Sep 2008 16:21:12 +0400, Frank Benoit <keinfarbton googlemail.com> wrote:This one still prevents me from sleepping :) You can use : palette.Entries.ptr[i] to prevend array bound checking made by: palette.Entries[i] instead of unpleasant: *(palette.Entries.ptr + i)Denis Koroskin Wrote:Ouch! Are you sure this fixes the issue and not hides it? It's quite clear that the bug is somewhere else, colorPalette.Count == palette.Entries should always evaluate to true.On Mon, 01 Sep 2008 12:37:31 +0400, Denis Koroskin <2korden gmail.com> wrote:This was fixed in http://www.dsource.org/projects/dwt-win/changeset/302%3A555d58850cd9 can you please retry with the newest tip version? http://hg.dsource.org/projects/dwt-win/archive/tip.zip FrankOn Mon, 01 Sep 2008 11:32:36 +0400, Frank Benoit <keinfarbton googlemail.com> wrote: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;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
Sep 08 2008
Denis Koroskin Wrote:This one still prevents me from sleepping :) You can use : palette.Entries.ptr[i] to prevend array bound checking made by: palette.Entries[i] instead of unpleasant: *(palette.Entries.ptr + i)Hehe. This seems to me exactly the same code? But i admit, i like your syntax more.
Sep 08 2008
Frank Benoit schrieb:this code works for me. I will install SP3 to see if i can reproduce the problem.Works also with SP3 on my WinXp
Sep 01 2008