Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLTK and WIN10 and NMAKE #496

Closed
szukw000 opened this issue Sep 7, 2022 · 10 comments
Closed

FLTK and WIN10 and NMAKE #496

szukw000 opened this issue Sep 7, 2022 · 10 comments

Comments

@szukw000
Copy link

szukw000 commented Sep 7, 2022

@Albrecht-S ,
after several tests, installing msys64 I suppose I have found a bug in FLTK on WIN10
using NMAKE.

flimage*small-3.exe:
================
Fl_GDI_Graphics_Driver_image.cxx:182 TEST
Fl_GDI_Graphics_Driver_image.cxx:184 TEST
Fl_GDI_Graphics_Driver_image.cxx:395 TEST
Fl_GDI_Graphics_Driver_image.cxx:397 TEST
Fl_GDI_Graphics_Driver_image.cxx:395 TEST
Fl_GDI_Graphics_Driver_image.cxx:397 TEST

gdb:
====
Fl_GDI_Graphics_Driver_image.cxx:397 TEST
warning: HEAP[flimage-small-3.exe]:
warning: Heap block at 0000024014C9CE90 modified at 0000024014C9CED4 past requested size of 34

fltk*2022-08-09\src\drivers\GDI\Fl_GDI_Graphics_Driver_image.cxx:
======================================================
fprintf(stderr,"Fl_GDI_Graphics_Driver_image.cxx:%d TEST\n",__LINE__);
  bm = CreateBitmap(w, h, np, bpp, newarray);
fprintf(stderr,"Fl_GDI_Graphics_Driver_image.cxx:%d TEST\n",__LINE__);
  delete[] newarray; //<============================================= line 397
fprintf(stderr,"Fl_GDI_Graphics_Driver_image.cxx:%d TEST\n",__LINE__);

Likewise the debugger of 'Visual Studio 2022' stopped at 'delete'. But I could not
copy the lines from the debugger. So they are missing here.

winfried

@Albrecht-S
Copy link
Member

Albrecht-S commented Sep 7, 2022

@szukw000 Winfried, thank you for the report. Although I can see the line in question in the source code I can't guess what's happening here and what may be wrong with the code.

BTW: this code should be independent of the build system (NMake vs. VS msys64), it will be used by all Windows build systems.

What is your flimage-small-3.exe? Is it a small demo program and can you post the source code? Please be aware that we can't test your own application code to find a potential bug. We need a small test program (not longer than about 100 lines) to be able to debug. If a special image is needed to show the bug, please post this image as well.

Please post source code of a small, complete, program that shows the issue, and please give us instructions how to reproduce the issue. I'm sorry to say this: w/o a short test case we won't be able to debug this and this issue must be closed.

@Albrecht-S
Copy link
Member

Alternatively (rather than writing a small demo program) you can try if you can reproduce the issue with one of the FLTK test programs, for instance test/pixmap_browser.cxx. If you can find an image that exhibits the problem, please post this image file here. Looking at the code it might have to do with a special image encoding, hence we need the image file to analyze it.

@Albrecht-S
Copy link
Member

PS: before you continue testing, please make sure to download the latest code, preferably from Git, but the latest snapshot would be fine as well. Then tell us where you downloaded the software from, and the exact version (git commit or snapshot filename). Thanks.

@szukw000
Copy link
Author

@Albrecht-S ,
I have now found where the bug resides. See the attachment.
winfried
fltk-png-error.txt.zip

@Albrecht-S
Copy link
Member

@szukw000 Winfried, you wrote that you "found where the bug resides. See the attachment". This attachment is pretty useless (at least for me) without the code and the image file that causes it. Note however that we can't test and debug your code, even if the final error happens inside FLTK code.

3. src/drivers/GDIFl_GDI_Graphics_Driver_image.cxx
=====================================================
 // uchar *newarray = new uchar[(Bpr+pad)*h];
  uchar *newarray = new uchar[512 + (Bpr+pad)*h]; 

With this change the program now works without crash.

Where did you get the constant 512 from? Adding an arbitrary size to an array is not a fix if you (or we, the FLTK Team) don't know why the array is accessed out of bounds.

How to proceed:

  1. Please provide an image that fails (post it here).
  2. Please provide a test scenario that we can use to test the image.
  3. If possible, use one of the FLTK demo programs, e.g. test/pixmap_browser.
  4. If (3.) is not possible, please provide a small demo program that shows the issue (post it here).
  5. Please use the latest FLTK version (either from Git or a snapshot).
  6. Please answer the questions I asked above about which FLTK version you are using.

I may repeat myself, but this is essential: the code you refer to is not build system dependent, it is used on all Windows systems. Hence I assume that the real cause of the issue lies somewhere else in your code and the effects you see are caused by random program execution addresses which can exhibit the error if you build the program with VS/Nmake versus MinGW.

Without a working example and test image we need to close this issue.

@szukw000
Copy link
Author

@Albrecht-S ,
pointing to test/pixmap_browser is nice but useless. The bug is with building a table.
You can either HIDE building the table or HIDE drawing an image in small-5.1.0 .
winfried
gdi-error.txt.zip
small-5.1.0.zip

@erco77
Copy link
Contributor

erco77 commented Sep 29, 2022

Since this sounds Fl_Tree related, thought I'd look into this.
(Although the OP mentions a 'table', I don't see Fl_Table being used)

I was able to build the app you provided, but it won't load any valid PNG files I browse to.
It seems to give "EOF while reading" followed by "PNG_read_file(somefile.png) FAILED".

The app is too large to use as a simple debugging tool; I'm not sure what the app is supposed to do, or what the tree is used for.

OP, please reduce the problem to a simple one-file program.
If it's tree related, start with one of the simple tree examples (in examples/treecxx) and add code to it that demonstrates the crash.

@szukw000
Copy link
Author

@erco77 ,
OK, I give up.

In flimage.hh, line 92, you could find:

==================================================
class UserTree : public Fl_Tree
{
public:
    UserTree(int xx, int yy, int ww, int hh)
    : Fl_Tree(xx, yy, ww, hh, NULL)
    { }
    virtual int handle(int event);
};

extern UserTree *tree;
==================================================

In flimage.cxx, line 127, you could find:

==================================================
UserTree *tree = NULL;
//-----------------------------------------------

int UserTree::handle(int event)
{
    if(!Fl::event_inside(x(), y(), w(), h() ) )
   {
    return 0;
   }
    if(event == FL_LEAVE) return 1;

    return Fl_Tree::handle(event);
}
==================================================

In PNG.cxx, line 192, you could find:

==================================================
int PNG_read_file(Canvas *canvas, const char *read_idf, size_t fsize)
{
    int err;

    found_ACTL = 0;
//#ifdef HIDE_BUILD_TREE
//-------------------------------------
    FLImage_clear_tree();
//-------------------------------------

    err = png_build_tree(read_idf, fsize);

    if(err == 1) //FAILS
   {
    fprintf(stderr,"PNG.cxx:%d: png_build_tree fails\n",__LINE__);
    return 1;
   }
    return err;
//#endif
#ifdef HIDE_BUILD_IMAGE
    if( !found_ACTL)
   {
    err = png_load_file(canvas, read_idf, fsize);

    return err;
   }

    return 0;
#endif

}//PNG_read_file()
==================================================

So, it is true: if PNG.cxx is unchanged, no image will be shown.
Only the tree using LINUX.

If you wanted an image you had to HIDE_BUILD_TREE and (un-)HIDE_BUILD_IMAGE.

Bye.

winfried

@szukw000
Copy link
Author

@erco77 ,
and the famous WIN10 allowed to compile in the examples directory:

25.09.2022  16:39             2.342 Makefile
25.09.2022  16:39             1.829 Makefile.FLTK
               2 Datei(en),          4.171 Bytes
               0 Verzeichnis(se), 672.424.079.360 Bytes frei

C:\Users\szukw000\LIB\FLTK\fltk-1.4.x-2022-09-26-1\examples>nmake

Microsoft (R) Program Maintenance Utility, Version 14.33.31629.0
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Makefile.FLTK(32) : fatal error U1034: Syntaxfehler: Trennzeichen fehlt
Stop.

winfried

@erco77
Copy link
Contributor

erco77 commented Sep 29, 2022

> C:\Users\szukw000\LIB\FLTK\fltk-1.4.x-2022-09-26-1\examples>nmake

You have to be in the cmake "build" directory to build stuff.

If you want to build and run the FLTK examples with nmake, you'd use cmake with the build option FLTK_BUILD_EXAMPLES=on (builds of the examples are off by default):

cmake -G "NMake Makefiles" -D FLTK_BUILD_EXAMPLES=on -D CMAKE_BUILD_TYPE=Release ..
nmake

After that builds, you'd find the FLTK examples binaries in bin\examples\*.exe. So with Win10 + VS 2019 using the above cmake/nmake commands, I end up with:

Z:\tmp\fltk-1.4.x-git\build-nmake>dir bin\examples\*.exe
 Volume in drive Z is net
 Volume Serial Number is 2EB8-76D9

 Directory of Z:\tmp\fltk-1.4.x-git\build-nmake\bin\examples

09/29/2022  12:53 PM           622,080 browser-simple.exe
09/29/2022  12:55 PM           591,360 cairo-draw-x.exe
09/29/2022  12:53 PM           600,576 chart-simple.exe
09/29/2022  12:53 PM           574,976 draggable-group.exe
[..]
09/29/2022  12:55 PM           629,760 tree-custom-sort.exe
09/29/2022  12:54 PM           659,456 tree-of-tables.exe
09/29/2022  12:55 PM           627,712 tree-simple.exe
09/29/2022  12:55 PM           615,936 wizard-simple.exe
              38 File(s)     23,666,688 bytes
               0 Dir(s)  499,737,956,352 bytes free

Z:\tmp\fltk-1.4.x-git\build-nmake>

OK, I give up.

Yes, well next time please reduce the problem as requested by the developers. We shouldn't have to comb through a zip file containing 42 files and 2700 lines of code. That's basically like saying 'here debug my program'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants