Optiroc / SuperFamiconv

Flexible and composable tile graphics converter supporting Super Nintendo, Game Boy, Game Boy Color, Game Boy Advance, Mega Drive, PC Engine and WonderSwan formats.
MIT License
143 stars 20 forks source link

100% cpu usage infinite loop on Windows #4

Closed ARM9 closed 7 years ago

ARM9 commented 7 years ago

When starting the program, regardless of argv, it gets stuck in an infinite loop doing nothing but burning cycles. Has anyone ran this successfully on Windows? Is this a known issue?

I discovered this a while back but I forgot about it, I'll get to debugging it proper later, just posting this as a reminder.

Windows 8.1 x64, tdm-gcc (mingw-w64 5.1.0, I forget threads/exceptions used, probably posix+dwarf)

Optiroc commented 7 years ago

Thanks for the heads up – it's an unknown issue until now (Windows is pretty much unknown territory to me at this point)... Maybe it's the getopts-wrapper.

I'll try to get someone (ping @breakin !) to compile and see what's up.

ARM9 commented 7 years ago

Optimizations seem to be part of the problem, building with -O0 works so I'll use that for now, if I use any higher level it'll crash. Only had a moment to debug, but it dies in an Options::Add call. For anyone building with mingw, replace sys/ioctl.h with winsock.h.

Optiroc commented 7 years ago

OK, interesting. I would've assumed that something would trip up in Options::Parse, not Options:Add. I must find a way to debug gcc generated code.

Happy to see that you find the tool somewhat useful, bugs notwithstanding! (: It would be neat to be able to distribute working binaries for both Mac and Windows at some not too far off point in the future.

Optiroc commented 7 years ago

@ARM9 I got around to set up a Windows VM during the weekend and fiddled around a bit with the available toolchains (Visual Studio 2017 seemed like a good choice in theory, but I found it completely incomprehensible).

Using the mingw toolchain in a cygwin environment I think I've produced working Windows binaries. I decided to statically link the runtime library, so the binary came out at 12MB uncompressed... Argument parsing seems to work fine, but I encountered crashes with huge input images (like a full mode 7 background). Maybe you need to set a larger stack size manually?

Anyway, here's a binary! I believe it will only run on x64 Windows. I should look into how to build x86 binaries too, but ran out of patience with Windows for the time being... (:

Optiroc commented 7 years ago

I should probably give Visual Studio another shot. For one I good use the easier debugging environment, and I don't feel entirely comfortable with the unnecessary overhead of the mingw libraries.

Optiroc commented 7 years ago

I experimented a bit more with the cygwin/mingw setup, and together with Undisbelievers libstdc++ fix the binary seems to work with everything I've thrown at it in my Windows 7 x64 VM.

If anyone who's interested in a pre-built windows binary happens to read this, please check out the v0.3 release!

ARM9 commented 7 years ago

That's great, I haven't gotten around to testing your binaries yet but I believe it, stoked for you dude. If you're going to switch to VC++ you'll want to adopt cmake or provide a visual studio solution in addition to the gnu makefile (.vsproj/.sln or whatever). Are you building with optimizations for Windows?

Optiroc commented 7 years ago

The current Windows build is made on cygwin/mingw32-gcc with libstdc++ statically linked, so the filesize is rather enormous but at least it seems to work fine now (at least on my stock Windows 7 x64 install in a normal cmd.exe session). It's built with optimization level -O3 but no LTO.

I should probably take a stab at building with a CMake/VC++ setup.

Optiroc commented 7 years ago

I gave VS2017 and CMake on Windows 7 another shot, but the amount of grief that combination of software gives me is just too much... :D The CMakeList.txt I whipped together generates builds just fine on OSX, but got me into a rabbit hole of errors and missing dll's on Windows.

CMakeLists.txt

cmake_minimum_required (VERSION 3.6)
project (superfamiconv)

set(CMAKE_CXX_STANDARD 11)
add_definitions(-DSFC_MONOLITH)
include_directories(include)

set(SOURCES include/LodePNG/lodepng.cpp src/superfamiconv.cpp src/sfc_palette.cpp src/sfc_tiles.cpp src/sfc_map.cpp src/Image.cpp src/Map.cpp src/Palette.cpp src/Tiles.cpp)

add_executable(superfamiconv ${SOURCES})
ARM9 commented 7 years ago

This problem seems to have been resolved, I was unable to reproduce the behaviour on Windows 8.1 with the latest commit.

Optiroc commented 7 years ago

Great! I'll check out your PR later tonight!