Giter Site home page Giter Site logo

examples build KO about libsfx HOT 11 CLOSED

rimaille avatar rimaille commented on August 17, 2024
examples build KO

from libsfx.

Comments (11)

undisbeliever avatar undisbeliever commented on August 17, 2024 1

superfamiconv also crashes on my machine (Arch Linux x64, g++).

gdb wasn't helpful, so I switched to valgrind, which gave:

==15484== Invalid write of size 4
==15484==    at 0x43DA91: void std::__unguarded_linear_insert<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Val_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}> >(__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Val_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>) (stl_algo.h:1827)
==15484==    by 0x439B5F: void std::__unguarded_insertion_sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}> >(__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>) (stl_algo.h:1864)
==15484==    by 0x433AAF: void std::__final_insertion_sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}> >(__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>) (stl_algo.h:1883)
==15484==    by 0x42FAC0: void std::__sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}> >(__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>, __gnu_cxx::__ops::_Iter_comp_iter<sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>) (stl_algo.h:1968)
==15484==    by 0x42D571: void std::sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}>(__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}, sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&)::{lambda(unsigned int const&, unsigned int const&)#1}) (stl_algo.h:4739)
==15484==    by 0x42C60A: sfc::sort_colors(std::vector<unsigned int, std::allocator<unsigned int> >&) (Common.h:329)
==15484==    by 0x42CF9B: sfc::Subpalette::sort() (Palette.h:63)
==15484==    by 0x42A6B6: sfc::Palette::sort() (Palette.cpp:51)
==15484==    by 0x41B3A5: sfc_palette(int, char**) (sfc_palette.cpp:159)
==15484==    by 0x4077B9: main (superfamiconv.cpp:225)

Testing has confirmed that the bug is in the comparison lambda in sfc::sort_colors. Apparently gnu libstdc++ std::sort can write outside the vector and crash if the comparison function does not honour strict weak ordering.

I couldn't see any reason why sfc::rgba_color::operator> did not honour strict weak ordering, but on a whim I did this:

diff --git a/src/Common.h b/src/Common.h
index 1254762..783a8cc 100644
--- a/src/Common.h
+++ b/src/Common.h
@@ -320,7 +320,7 @@ inline bool rgba_color::operator>(const rgba_color& o) const {
   int lo = (int)(segments * sqrt(0.241f * o.r + 0.691f * o.g + 0.068f * o.b));
   int vo = (int)(segments * hsva_o.v);
 
-  return (h > ho) ? true : (l > lo) ? true : (v > vo) ? true : false;
+  return std::tie(h, l, v) > std::tie(ho, lo, vo);
 }
 
 inline void sort_colors(std::vector<rgba_t>& colors) {

And the crash went away on my system.

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

Hi! Hmm, yeah, SuperFamiconv seems to struggle with large input images when built with gcc (like the Mode 7 backgrounds in those examples). I'll try to get a decent debugging environment up and running to diagnose those...

The SuperFX example isn't supposed to do anything but set the background color – it's just a test for the assembly output basically.

from libsfx.

rimaille avatar rimaille commented on August 17, 2024

Ok for SuperFX example, so sfc works. But i did provided the output for this error :
ld65: Error: Missing memory area assignment for segment `ZNMI'
make: *** [../../libSFX.make:182: SuperFX.sfc] Error 1
exit code 2

I tried compiling SuperFamiconv with clang++, but i got problems with the linker. I switched ld to gold, -fuse-ld=gold as many forums said, but no luck so far (invalid character/syntax error invalid end in *.o).

If you need help to diagnose the famiconv problem, feel free to ask, i'll do my best.

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

Ah, good catch. I need to update the memory map for that one.

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

The GSU/SuperFX memory map is now fixed.

Regarding the trouble with SuperFamiconv: do you have any experience with debugging using gdb (or any graphical frontend for it)? It would certainly be of great help to get more information about the crashes!

from libsfx.

rimaille avatar rimaille commented on August 17, 2024

Thanks, i can confirm that SuperFX example is now building without error.

Unfortunately, i have no experience with debugging using gdb. However, i uploaded the core file, with the binary compiled with gcc (debug enabled) :

core.zip
superfamiconv.zip

I don't know if it's usefull, please tell me what i can do :
http://sprunge.us/bajV
(please note the truncated arguments Core was generated by `../../tools/superfamiconv/bin/superfamiconv -9 ette -v --colors 128 --in-image'.)

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

Wow, that's really helpful, thanks! It's amazing how many things works just fine using clang/libc++ that wreaks complete havoc with gcc/libstdc++, actually.

from libsfx.

rimaille avatar rimaille commented on August 17, 2024

@undisbeliever your patch worked for me, thank you

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

@undisbeliever Ohh, you're a star!

from libsfx.

rimaille avatar rimaille commented on August 17, 2024

@Optiroc

On a side, when i launched make for Mode7-Transform, i had to modify the shebang of Sin.py
Yours was pointing to /usr/local/bin when mine and potentially all linux distribution point to /usr/bin
Is there any way to make it "universal" (i mean that could work out of the box for all of us) ?

from libsfx.

Optiroc avatar Optiroc commented on August 17, 2024

@rimaille Ah, that's really just an old habit of mine, but in this case there's really no reason not to use the python distributed with the OS (even macOS doesn't lag behind too horribly on python 2.x anymore).

from libsfx.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.