Universal-Team / pkmn-chest

A Pokémon Bank for the 3rd through 5th generation Pokémon games for the Nintendo DS(i).
https://universal-team.net/projects/pkmn-chest
GNU General Public License v3.0
215 stars 10 forks source link

[Bug Report] Unable to transfer japanese pokemon from gen III to european gen IV. #87

Open sergiotarxz opened 2 months ago

sergiotarxz commented 2 months ago

Describe the bug Cannot transfer japanese pokemons from gen III to an european gen IV game. std::bad_alloc

Console (please complete the following information):

Additional context Add any other context about the problem here.

sergiotarxz commented 2 months ago

I got a stacktrace:

#0  0x0210b418 in __cxa_throw ()
#1  0x0210ba9c in operator new(unsigned int) ()
#2  0x0201d1ac in std::__new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate (this=<optimized out>, 
    __n=<optimized out>) at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/new_allocator.h:147
#3  std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate (__n=<optimized out>, this=<optimized out>)
    at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/allocator.h:198
#4  std::allocator_traits<std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocate (__n=<optimized out>, __a=...)
    at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/alloc_traits.h:482
#5  std::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_allocate (this=<optimized out>, __n=<optimized out>) at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/stl_vector.h:378
#6  std::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_allocate (__n=<optimized out>, this=<optimized out>) at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/stl_vector.h:375
#7  std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__position=..., this=0xb0039d4)
    at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/vector.tcc:459
#8  std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::emplace_back<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (this=0xb0039d4)
    at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/vector.tcc:123
#9  i18n::load (lang=lang@entry=pksm::Language::JPN, name=..., array=...) at /home/sergio/pkmn-chest/arm9/core/source/i18n/i18n.cpp:177
#10 0x020253f4 in i18n::initMove (lang=pksm::Language::JPN) at /opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/bits/basic_string.tcc:238
#11 0x0201bbc0 in i18n::init (lang=pksm::Language::JPN) at /home/sergio/pkmn-chest/arm9/core/source/i18n/i18n.cpp:94
#12 0x02026b40 in i18n::checkInitialized (lang=<optimized out>) at /home/sergio/pkmn-chest/arm9/core/source/i18n/i18n_internal.hpp:75
#13 i18n::species[abi:cxx11](pksm::Language, pksm::Species) (lang=<optimized out>, val=...) at /home/sergio/pkmn-chest/arm9/core/source/i18n/i18n_species.cpp:45
#14 0x02026ba0 in pksm::internal::Species_impl::localize[abi:cxx11](pksm::Language) const (this=this@entry=0xb003a88, lang=<optimized out>)
    at /home/sergio/pkmn-chest/arm9/core/source/i18n/i18n_species.cpp:69
#15 0x020313e4 in pksm::Species::localize[abi:cxx11](pksm::Language) const (lang=<optimized out>, this=0xb003a88)
    at /home/sergio/pkmn-chest/arm9/core/include/enums/Species.hpp:1072
#16 pksm::PK3::convertToG4 (this=0x23a2540) at /home/sergio/pkmn-chest/arm9/core/source/pkx/PK3.cpp:572
#17 0x02061860 in pksm::Sav::transfer (this=this@entry=0x21ac100, pk=...) at /home/sergio/pkmn-chest/arm9/core/source/sav/Sav.cpp:197
#18 0x02019258 in manageBoxes () at /home/sergio/pkmn-chest/arm9/source/manager.cpp:699
#19 0x020105b0 in mainLoop () at /home/sergio/pkmn-chest/arm9/source/main.cpp:141
#20 0x020d97b8 in main (argc=1, argv=<optimized out>) at /home/sergio/pkmn-chest/arm9/source/main.cpp:163
sergiotarxz commented 2 months ago

I was able to make it work with the following not so clean patch on arm9/core:

diff --git a/source/i18n/i18n_species.cpp b/source/i18n/i18n_species.cpp
index 7181002..f0caf37 100644
--- a/source/i18n/i18n_species.cpp
+++ b/source/i18n/i18n_species.cpp
@@ -42,7 +42,8 @@ namespace i18n

     const std::string& species(pksm::Language lang, pksm::Species val)
     {
-        checkInitialized(lang);
+        speciess.erase(lang);
+        i18n::load(lang, "/species.txt", speciess[lang]);
         if (speciess.count(lang) > 0)
         {
             if (size_t(val) < speciess[lang].size())