Hi,

I tried running my program under Valgrind to look for any pesky memory 
corruption bugs, but in addition to taking an inordinately long time to start 
up (e.g. creating the font atlas takes 3 minutes), I get a lot of errors about 
invalid reads and writes such as those listed in this attachment. What really 
baffles me is that they show that the reads happened in a region of allocated 
memory.

My initial guess is that it has something to do with my program handling memory 
very weirdly: some of the code switches the stack pointer in order to implement 
coroutines. In fact, Valgrind does warn of this.

My code is here in case anyone actually wants to try it:
https://gitlab.com/nagakawa/tdr

– T

==10767== Warning: client switching stacks?  SP change: 0x1ffefff490 --> 
0xa628318
==10767==          to suppress, use: --max-stackframe=137247945080 or greater
start shot task
==10767== Invalid write of size 8
==10767==    at 0x160941: kcrManagerYieldEx (kcr.c:563)
==10767==    by 0x160A18: kcrYieldEx (kcr.c:589)
==10767==    by 0x1352A5: kcr::yield() 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:227)
==10767==    by 0x1299B4: 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>&&)::$_0::operator()() const (TestGame.cpp:259)
==10767==    by 0x12995D: void std::__invoke_impl<void, 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>&&)::$_0&>(std::__invoke_other, 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&)::$_0&) 
(invoke.h:60)
==10767==    by 0x12994D: 
std::__invoke_result<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel,
 TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&>::type 
std::__invoke<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> 
>&&)::$_0&>(TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&) (invoke.h:95)
==10767==    by 0x12993D: decltype(auto) 
std::__apply_impl<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel,
 TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&, 
std::tuple<>&>(TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&, std::tuple<>&, std::integer_sequence<unsigned long>) 
(tuple:1678)
==10767==    by 0x12990E: decltype(auto) 
std::apply<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&, 
std::tuple<>&>(TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&, std::tuple<>&) (tuple:1687)
==10767==    by 0x129821: void 
kcr::proxyCallback<std::tuple<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel,
 TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0, kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawn<TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel,
 TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> 
>&&)::$_0>(TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, 
TDRTestView, TestSharedData, std::variant<Graze, Hit, ScorePopup, 
SetBossSprite> >&&)::$_0&&)::{lambda()#1}, std::tuple<> > >(void*) 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:114)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==    by 0x5: ???
==10767==  Address 0xa62a018 is 8 bytes inside a block of size 48 alloc'd
==10767==    at 0x483877F: malloc (vg_replace_malloc.c:299)
==10767==    by 0x15F47D: kcrManagerCreate (kcr.c:136)
==10767==    by 0x133658: kcr::Manager::Manager() 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:198)
==10767==    by 0x12C37F: tdr::GameModel<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::GameModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(include/TDR/Game.h:100)
==10767==    by 0x1271CC: 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(TestGame.cpp:225)
==10767==    by 0x1418F5: void std::_Optional_base_impl<TDRTestModel, 
std::_Optional_base<TDRTestModel, false, false> 
>::_M_construct<tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> > 
>(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) (optional:629)
==10767==    by 0x13F721: 
_ZNSt8optionalI12TDRTestModelE7emplaceIJN3tdr16GameModelOptionsIS0_11TDRTestView14TestSharedDataSt7variantIJ5Graze3Hit10ScorePopup13SetBossSpriteEEEEEEENSt9enable_ifIXsr16is_constructibleIS0_DpOT_EE5valueERS0_E4typeESH_
 (optional:1140)
==10767==    by 0x13F356: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::startStage(unsigned int) (include/TDR/Game.h:817)
==10767==    by 0x12E168: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::initialise() (include/TDR/Game.h:698)
==10767==    by 0x149FD4: 
_ZN3agl21ScenedGLFWApplicationI14TestSharedDataE11insertSceneI11TDRTestViewEENSt9enable_ifIXsr3stdE12is_base_of_vINS_5SceneIS1_EET_EEPS8_E4typeEOSt10unique_ptrIS8_St14default_deleteIS8_EE
 (include/AGL/ScenedGLFWApplication.h:116)
==10767==    by 0x1496D3: test(char const*) (Test.cpp:75)
==10767==    by 0x1498BA: main (Test.cpp:107)
==10767== 
==10767== Invalid read of size 8
==10767==    at 0x145611: TDRTestStage0::initialise()::$_1::operator()() const 
(stage0.cpp:40)
==10767==    by 0x1454C1: void 
kcr::proxyCallback<std::tuple<TDRTestStage0::initialise()::$_1, 
kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawn<TDRTestStage0::initialise()::$_1>(TDRTestStage0::initialise()::$_1&&)::{lambda()#1},
 std::tuple<> > >(void*) 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:114)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==  Address 0xa62a1e0 is 0 bytes inside a block of size 8 alloc'd
==10767==    at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:334)
==10767==    by 0x1453F6: kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawnTeardown<TDRTestStage0::initialise()::$_1&, 
kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawn<TDRTestStage0::initialise()::$_1>(TDRTestStage0::initialise()::$_1&&)::{lambda()#1}>(TDRTestStage0::initialise()::$_1&&,
 kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawn<TDRTestStage0::initialise()::$_1>(TDRTestStage0::initialise()::$_1&&)::{lambda()#1}&&)
 (3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:155)
==10767==    by 0x144BF6: TDRTestStage0::initialise() (stage0.cpp:40)
==10767==    by 0x12C46D: tdr::GameModel<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::GameModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(include/TDR/Game.h:489)
==10767==    by 0x1271CC: 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(TestGame.cpp:225)
==10767==    by 0x1418F5: void std::_Optional_base_impl<TDRTestModel, 
std::_Optional_base<TDRTestModel, false, false> 
>::_M_construct<tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> > 
>(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) (optional:629)
==10767==    by 0x13F721: 
_ZNSt8optionalI12TDRTestModelE7emplaceIJN3tdr16GameModelOptionsIS0_11TDRTestView14TestSharedDataSt7variantIJ5Graze3Hit10ScorePopup13SetBossSpriteEEEEEEENSt9enable_ifIXsr16is_constructibleIS0_DpOT_EE5valueERS0_E4typeESH_
 (optional:1140)
==10767==    by 0x13F356: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::startStage(unsigned int) (include/TDR/Game.h:817)
==10767==    by 0x12E168: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::initialise() (include/TDR/Game.h:698)
==10767==    by 0x149FD4: 
_ZN3agl21ScenedGLFWApplicationI14TestSharedDataE11insertSceneI11TDRTestViewEENSt9enable_ifIXsr3stdE12is_base_of_vINS_5SceneIS1_EET_EEPS8_E4typeEOSt10unique_ptrIS8_St14default_deleteIS8_EE
 (include/AGL/ScenedGLFWApplication.h:116)
==10767==    by 0x1496D3: test(char const*) (Test.cpp:75)
==10767==    by 0x1498BA: main (Test.cpp:107)
==10767== 
==10767== Invalid write of size 8
==10767==    at 0x160941: kcrManagerYieldEx (kcr.c:563)
==10767==    by 0x160A18: kcrYieldEx (kcr.c:589)
==10767==    by 0x1352A5: kcr::yield() 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:227)
==10767==    by 0x139744: tdr::cwait(unsigned long) (include/TDR/yield.h:15)
==10767==    by 0x14561D: TDRTestStage0::initialise()::$_1::operator()() const 
(stage0.cpp:41)
==10767==    by 0x1454C1: void 
kcr::proxyCallback<std::tuple<TDRTestStage0::initialise()::$_1, 
kcr::ManagerObserver::Entry 
kcr::ManagerObserver::spawn<TDRTestStage0::initialise()::$_1>(TDRTestStage0::initialise()::$_1&&)::{lambda()#1},
 std::tuple<> > >(void*) 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:114)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==    by 0x160B34: ??? (switch.s:46)
==10767==  Address 0xa62a018 is 8 bytes inside a block of size 48 alloc'd
==10767==    at 0x483877F: malloc (vg_replace_malloc.c:299)
==10767==    by 0x15F47D: kcrManagerCreate (kcr.c:136)
==10767==    by 0x133658: kcr::Manager::Manager() 
(3rdparty/agc/kozet_coroutine/include/kozet_coroutine/kcr.h:198)
==10767==    by 0x12C37F: tdr::GameModel<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::GameModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(include/TDR/Game.h:100)
==10767==    by 0x1271CC: 
TDRTestModel::TDRTestModel(tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) 
(TestGame.cpp:225)
==10767==    by 0x1418F5: void std::_Optional_base_impl<TDRTestModel, 
std::_Optional_base<TDRTestModel, false, false> 
>::_M_construct<tdr::GameModelOptions<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> > 
>(tdr::GameModelOptions<TDRTestModel, TDRTestView, TestSharedData, 
std::variant<Graze, Hit, ScorePopup, SetBossSprite> >&&) (optional:629)
==10767==    by 0x13F721: 
_ZNSt8optionalI12TDRTestModelE7emplaceIJN3tdr16GameModelOptionsIS0_11TDRTestView14TestSharedDataSt7variantIJ5Graze3Hit10ScorePopup13SetBossSpriteEEEEEEENSt9enable_ifIXsr16is_constructibleIS0_DpOT_EE5valueERS0_E4typeESH_
 (optional:1140)
==10767==    by 0x13F356: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::startStage(unsigned int) (include/TDR/Game.h:817)
==10767==    by 0x12E168: tdr::GameView<TDRTestModel, TDRTestView, 
TestSharedData, std::variant<Graze, Hit, ScorePopup, SetBossSprite> 
>::initialise() (include/TDR/Game.h:698)
==10767==    by 0x149FD4: 
_ZN3agl21ScenedGLFWApplicationI14TestSharedDataE11insertSceneI11TDRTestViewEENSt9enable_ifIXsr3stdE12is_base_of_vINS_5SceneIS1_EET_EEPS8_E4typeEOSt10unique_ptrIS8_St14default_deleteIS8_EE
 (include/AGL/ScenedGLFWApplication.h:116)
==10767==    by 0x1496D3: test(char const*) (Test.cpp:75)
==10767==    by 0x1498BA: main (Test.cpp:107)
==10767== 

_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to