SpartanJ / SOIL2

SOIL2 is a tiny C library used primarily for uploading textures into OpenGL.
MIT No Attribution
370 stars 75 forks source link

SSE2 implementation of JPEG loader crashes on 32bit builds. #5

Closed SpartanJ closed 9 years ago

SpartanJ commented 9 years ago

Original report by RoestVrijStaal (Bitbucket: RoestVrijStaal, GitHub: RoestVrijStaal).


Hello,

I try to compile SOIL2 but my attempts with standalone MinGW-w64 with its own command line and Code::Blocks inclusive MinGW-64 failed.

The most successful result was with Code::Blocks after adding -msse2 as extra compiler flag.

However, test_perf_SOIL2.cpp SIGSEGs in SSE2 instructions again.

Which compiler + flags (and IDE) do you use?

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


I doesn't need any compiler flag in particular, it should work without problems with MingW-64 ( it's what i'm using by the way ). May be you can share me your test project to see if i see something wrong, and also send me the image that's segfaulting. You can also try to compile it generating the Makefiles with premake4. Just download premake4 and do premake4 gmake, it will generate the Makefile in make/windows subfolder.

SpartanJ commented 9 years ago

Original comment by RoestVrijStaal (Bitbucket: RoestVrijStaal, GitHub: RoestVrijStaal).


I tried to compile SOIL2 with premake4 in the beginning, but make / mingw32-make ignores environment variables so I gave up on trying to compile via command line.

After experimenting, I noticed it seem only to apply to jpeg loading. At other formats like bmp, png and tga loading and using goes fine.

I tried different jpgs, but it ends up in the same result.

The segmentation fault occurs in emmintrin.h, rule 670, initiated by rule 1508 in stb_image.c.

// emmintrin.h (r605)

return extension (m128i)(v8hi){ q0, q1, q2, q3, q4, q5, q6, q7 };

// stb_image.c (r1508)

m128i rot0_0 = dct_const(stbif2f(0.5411961f), stbif2f(0.5411961f) + stbif2f(-1.847759065f));

ATM I'm using MinGW-w64 i686-4.9.2-posix-dwarf-rt_v3-rev1 on Win7 x84_64. The same occurs on a Win7 x86_32.

Here are the links to the test projects:

http://go4up.com/dl/d8ee78678e79/SpartanJ-soil2__test_perf_SOIL2.rar

http://go4up.com/dl/de0a9112f8fb/SpartanJ-soil2__test_SOIL2.rar

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


It seems to be a compilation problem, since i compiled the project by myself and worked fine with jpgs, but your project crashes with the jpg files. I pushed some minor fixes to the JPG SSE2 implementation in stb_image, but i don't think that was your problem.

I used TDM-GCC, i'm not using the same mingw as you, so, i recommend you to try it. You should not have the SDL2 include problem, just copy the files as they come in the SDL2 for mingw file and it'll work.

Before doing anything pull and update the SOIL2 repo with the new changes.

Please try to compile the project again updating the repository, creating the project width premake4 ( premake4 gmake or premake4 codeblocks ), and try to use TDC-GCC that it's working fine, copy the SDL2 stuff to the TDM-GCC folder ( copy the x86_64-w64-mingw32 directory, that's what you should be using for x64, otherwise i686-w64-mingw32 ), and that should be enough.

Regards

SpartanJ commented 9 years ago

Original comment by CHAOS-THEORY (Bitbucket: CHAOS-THEORY, GitHub: CHAOS-THEORY).


Yo ! wassup, I can't believe i registered here and i don't even know what this website is up for lel. Anyway, since i saw you had that issue into your website notification toolbar i decided to put ma noise in and tell you that it compiled fine under GNU GCC Compiler in a 32b architecture with the default settings, 0Warns 0Errors. So it shouldn't be an issue here, you might remove it as it faked me that this library is in alpha release and will be causing troubles for my future development and am sure it will fake other users as well; Here i'll point you out a bit just to take out all the useless prethinking over the author's head. < I couldn't know a good place to put this tiny tutorial in so i ll just post here > < Please wait for the images if they are slow to load (the images i uploaded) > In CODE::BLOCKS (am using the latest version and so should you).

Project - New.png

Now that you are here with a new Static Lib. project.

delete from project.png

add files recursively.png

Select all and oke.png

files added.png

build bytch.png

Else if you followed this tut correctly and failed, please report back with all the errors and warnings returned by your compiler.

succces nigga.png

And finally i have uploaded it for you, the whole project including the library compiled if you ever need it. And don't forget am using the 32b architecture under winxp, go ahead and use it compile it.

SOIL2 - LIB - AK' Download < Hosted by OneDrive >

< Updated, added the release Lib as well >

Good luck and Peace yo !

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Wow, that's a lot of work, thanks for the comment. But i must say that it wasn't necessary. The premake file that comes with the project it's exactly to avoid all that work, since you can just make premake4.exe codeblocks and it ill generate the projects ( the static lib and the demos ) in the sub-folder make\windows inside the project, and it works just fine, the only thing that you may want to change is the executable directory, since it's not detected correctly by premake. I'll add this information in the project README to avoid confusion.

Regards!

SpartanJ commented 9 years ago

Original comment by CHAOS-THEORY (Bitbucket: CHAOS-THEORY, GitHub: CHAOS-THEORY).


An i actually didn't notice it till now, ma bad since i didn't read the whole post and skipped directly to compiling from codeblocks, thought it would be better to just give a graphical view on how to compile it to have a better understanding on the error. Well peace yo !

SpartanJ commented 9 years ago

Original comment by RoestVrijStaal (Bitbucket: RoestVrijStaal, GitHub: RoestVrijStaal).


Hello,

I tried to reproduce the bug with TDM-GCC, but I couldn't set up the toolchain properly because TDM-GCC installs the 64-bit compiler and I'm using 32-bit Windows. The TDM-GCC docs tells using -m32 would work, but since other dlls are used, it doesn't.

Trying to the "old" MinGW environment installed by TDM-GCC doesn't play nice with SDL2 either.

The installation process of TDM-GCC makes me wonder if difference between things like SJLJ, SEH and DWARF2 and POSIX / Win32 threads could cause the jpg-view problem. I know they shouldn't, but it could be.

Are the used jpg-loading dll's the same? To compare, you'll find the one I use (libjpeg-9.dll) in the \bin\Debug directory of the uploaded projects I linked to in the previous post. It's the one shipped with SDL2_image-2.0.0.

Please notice I'm able to build SOIL2 in the beginning, but I felt something was wrong because I had to add -msse2 to get a successful build. I guess the title of this issue is somewhat misleading now, because it seems only jpg-view doesn't work. Sorry for your efforts CHAOS-THEORY, but likely someone else will find it a handy tutorial.

Since it seems only a problem with jpg. I guess working it around by using other file formats is my best option for the time being.

Best Regards,

RoestVrijStaal

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


OK, so now i understand the problem!

The new stb_image SSE2 jpeg decoder implementation is not working on 32bit builds. Sadly i didn't see the problem before, but this is a new introduced bug because i updated the image loader library that SOIL2 uses and it's bugged. So i'll report the bug to the mantainer.

Meanwhile i disabled SSE2 in 32bit builds, that fixes the problem. I don't know if this is a Window only problem, i'll test it in some minutes so i can report the bug correctly in the stb_image repo.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Reopened until the SSE2 implementation is fixed.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Disabled SSE2 for 32bit builds since it's crashing the application! See issue #5.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


RoestVrijStaal, just to let you know:

To compile with TDM-GCC64 in 32bits, it's OK to use -m32, that should work. SDL2 works OK, but you should know how to make it work, this is what you have to do ( otherwise it will not link against your 32bit build ): Copy the files from the SDL2 mingw package that are inside i686-w64-mingw32\lib\ to TDM-GCC-64\x86_64-w64-mingw32\lib32. That's all, and of course, copy the include files, and put the SDL2.dll lib with your exe, but the 32 bit one, the one that is on \i686-w64-mingw32\bin\.

To generate the project with 32bit forced with premake you should do premake4 --platform=x32 gmake ( or codeblocks or whatever ).

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


More data: Compiled with VC ( VS2013 ) in 32bits works just fine! So it must be a problem with the generated SSE2 code in mingw, totally weird. I'm going to test a little bit more.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Disable SSE2 jpeg decoding only for mingw32 32 bit builds. See Issue #5.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Issue on github: https://github.com/nothings/stb/issues/81

SpartanJ commented 9 years ago

Original comment by RoestVrijStaal (Bitbucket: RoestVrijStaal, GitHub: RoestVrijStaal).


It's kinda overwhelming for me. What should I do now?

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Just pull and update the repo and recompile. It should work because i disabled SSE2 for 32bit mingw builds.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Fixed issue #5.