Allegro Heap corruption (I think).
mijgame

Hello everyone. I'm new, so hi ;D

I am currently having an issue with my Heap corrupting. And after a couple hours of pulling my hair out, Application Verifier gives the following output:

#SelectExpand
1<?xml version="1.0" encoding="UTF-8"?> 2 3-<avrf:logfile xmlns:avrf="Application Verifier"> 4 5 6-<avrf:logSession Version="2" PID="7636" TimeStarted="2015-08-07 : 19:52:14"> 7 8 9-<avrf:logEntry Severity="Error" StopCode="0x206" LayerName="Locks" Time="2015-08-07 : 19:52:15"> 10 11<avrf:message>Invalid critical section owner thread.</avrf:message> 12 13<avrf:parameter1>c136fcc - Critical section address. Run !cs -s <address> to get more information.</avrf:parameter1> 14 15<avrf:parameter2>20d4 - Owning thread.</avrf:parameter2> 16 17<avrf:parameter3>18e8 - Expected owning thread.</avrf:parameter3> 18 19<avrf:parameter4>c13efe0 - Critical section debug info address.</avrf:parameter4> 20 21 22-<avrf:stackTrace> 23 24<avrf:trace>vfbasics!+556b8d71 ( @ 0)</avrf:trace> 25 26<avrf:trace>vfbasics!+556b96b1 ( @ 0)</avrf:trace> 27 28<avrf:trace>allegro-5.0.10-monolith-md!al_cond_timedwait+eb ( @ 0)</avrf:trace> 29 30</avrf:stackTrace> 31 32</avrf:logEntry> 33 34</avrf:logSession> 35 36</avrf:logfile>

The line allegro-5.0.10-monolith-md!al_cond_timedwait+eb ( @ 0) catches my eye. The program crashes on al_wait_for_event(event_queue, &ev); everytime (Visual Studio 2015 breaks at a breakpoint on that line everytime I run my program).

So what do you make of this? I'm kinda at a loss.
Thanks.

Thomas Fjellstrom

memory corruption is usually a PEBKAC error, and is not always obvious where the problem is coming from.

Under linux i like to use valgrind to figure out where the error is comming from. I don't know of any equivalent on windows unfortunately.

mijgame

Hello,

An alternative for valgrind on Windows is Dr. Memory. It comes up with these results:

#SelectExpand
1LEAK 472 direct bytes 0x03677a40-0x03677c18 + 0 indirect bytes 2# 0 replace_calloc [d:\drmemory_package\common\alloc_replace.c:2417] 3# 1 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x6f7bd (0x6dfd2140 <allegro-5.0.10-monolith-md-debug+0x72140>) 4# 2 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x151fd4 (0x6e0b4957 <allegro-5.0.10-monolith-md-debug+0x154957>) 5# 3 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6e0260f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 6# 4 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6e0cac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 7# 5 MSVCR110D.dll!beginthreadex +0x1a0 (0x6d87e001 <MSVCR110D.dll+0x5e001>) 8# 6 MSVCR110D.dll!endthreadex +0x170 (0x6d87e1d1 <MSVCR110D.dll+0x5e1d1>) 9# 7 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x75787c04 <KERNEL32.dll+0x17c04>)

#SelectExpand
1HANDLE LEAK: USER handle 0x00010356 and 7 similar handle(s) were opened but not closed: 2# 0 system call NtUserCreateWindowEx 3# 1 USER32.dll!GetCapture +0x4e4 (0x773b18e5 <USER32.dll+0x118e5>) 4# 2 USER32.dll!GetCapture +0x6a0 (0x773b1aa1 <USER32.dll+0x11aa1>) 5# 3 USER32.dll!CreateWindowExA +0x36 (0x773b3397 <USER32.dll+0x13397>) 6# 4 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x164947 (0x6e0c72ca <allegro-5.0.10-monolith-md-debug+0x1672ca>) 7# 5 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x151efe (0x6e0b4881 <allegro-5.0.10-monolith-md-debug+0x154881>) 8# 6 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x15257e (0x6e0b4f01 <allegro-5.0.10-monolith-md-debug+0x154f01>) 9# 7 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6e0260f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 10# 8 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6e0cac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 11# 9 MSVCR110D.dll!beginthreadex +0x1a0 (0x6d87e001 <MSVCR110D.dll+0x5e001>) 12#10 MSVCR110D.dll!endthreadex +0x170 (0x6d87e1d1 <MSVCR110D.dll+0x5e1d1>) 13#11 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x75787c04 <KERNEL32.dll+0x17c04>) 14Note: @0:00:34.619 in thread 9356 15Note: handles created with the same callstack are closed here: 16Note: # 0 system call NtUserDestroyWindow 17Note: # 1 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x165a12 (0x6e0c8395 <allegro-5.0.10-monolith-md-debug+0x168395>) 18Note: # 2 USER32.dll!CallNextHookEx +0xb0 (0x773a8e71 <USER32.dll+0x8e71>) 19Note: # 3 USER32.dll!CallNextHookEx +0x310 (0x773a90d1 <USER32.dll+0x90d1>) 20Note: # 4 USER32.dll!CallNextHookEx +0x56b (0x773a932c <USER32.dll+0x932c>) 21Note: # 5 USER32.dll!CallNextHookEx +0x768 (0x773a9529 <USER32.dll+0x9529>) 22Note: # 6 ntdll.dll!KiUserCallbackDispatcher +0x35 (0x777407d6 <ntdll.dll+0x407d6>) 23Note: # 7 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x15286d (0x6e0b51f0 <allegro-5.0.10-monolith-md-debug+0x1551f0>) 24Note: # 8 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6e0260f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 25Note: # 9 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6e0cac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 26Note: #10 MSVCR110D.dll!beginthreadex +0x1a0 (0x6d87e001 <MSVCR110D.dll+0x5e001>) 27Note: #11 MSVCR110D.dll!endthreadex +0x170 (0x6d87e1d1 <MSVCR110D.dll+0x5e1d1>) 28Note: #12 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x75787c04 <KERNEL32.dll+0x17c04>)

Can you make something of this?
If you need more details / code, please ask.

Thomas Fjellstrom

Is there another mode that shows more than just leaks? valgrind also shows improper memory access (reads and writes), which is what we really need to see.

mijgame

Here is the full result:

#SelectExpand
1Dr. Memory version 1.8.1 build 0 built on Feb 17 2015 19:08:31 2Dr. Memory results for pid 6284: "Isselborgh Tycoon.exe" 3Application cmdline: ""C:\Users\Lex\Desktop\Isselborgh Tycoon\Debug\Isselborgh Tycoon.exe"" 4Recorded 108 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin\suppress-default.txt 5 6Error #1: UNINITIALIZED READ: reading 0x0087f2e8-0x0087f2ec 4 byte(s) 7# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 8# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 9# 2 GameConfiguration::Load [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\gameconfiguration.cpp:36] 10# 3 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:46] 11Note: @0:00:02.235 in thread 4276 12Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 13 14Error #2: UNINITIALIZED READ: reading 0x0087f2f0-0x0087f2f4 4 byte(s) 15# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 16# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 17# 2 GameConfiguration::Load [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\gameconfiguration.cpp:36] 18# 3 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:46] 19Note: @0:00:02.250 in thread 4276 20Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 21 22Error #3: UNINITIALIZED READ: reading 0x0087f2f4-0x0087f2f8 4 byte(s) 23# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 24# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 25# 2 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:43] 26# 3 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 27Note: @0:00:05.581 in thread 4276 28Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 29 30Error #4: UNINITIALIZED READ: reading 0x0087f2fc-0x0087f300 4 byte(s) 31# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 32# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 33# 2 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:43] 34# 3 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 35Note: @0:00:05.585 in thread 4276 36Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 37 38Error #5: UNINITIALIZED READ: reading 0x0087f0d4-0x0087f0d8 4 byte(s) 39# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 40# 1 FontManager::LoadFromList [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\fontmanager.cpp:21] 41# 2 MenuManager::CreateMenus [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\menumanager.cpp:36] 42# 3 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:45] 43# 4 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 44Note: @0:00:05.744 in thread 4276 45Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 46 47Error #6: UNINITIALIZED READ: reading 0x0087f0dc-0x0087f0e0 4 byte(s) 48# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 49# 1 FontManager::LoadFromList [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\fontmanager.cpp:21] 50# 2 MenuManager::CreateMenus [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\menumanager.cpp:36] 51# 3 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:45] 52# 4 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 53Note: @0:00:05.749 in thread 4276 54Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 55 56Error #7: UNINITIALIZED READ: reading 0x0087f0e4-0x0087f0e8 4 byte(s) 57# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 58# 1 FontManager::LoadFromList [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\fontmanager.cpp:21] 59# 2 MenuManager::CreateMenus [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\menumanager.cpp:36] 60# 3 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:45] 61# 4 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 62Note: @0:00:05.859 in thread 4276 63Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 64 65Error #8: UNINITIALIZED READ: reading 0x0087f198-0x0087f19c 4 byte(s) 66# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 67# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 68# 2 MenuManager::CreateMenus [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\menumanager.cpp:40] 69# 3 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:45] 70# 4 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 71Note: @0:00:05.879 in thread 4276 72Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 73 74Error #9: UNINITIALIZED READ: reading 0x0087f1a0-0x0087f1a4 4 byte(s) 75# 0 std::operator<<<> [d:\visual studio 2015\vc\include\ostream:797] 76# 1 LuaScript::Execute [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\luascript.cpp:80] 77# 2 MenuManager::CreateMenus [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\menumanager.cpp:40] 78# 3 Game::Initialize [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\game.cpp:45] 79# 4 main [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\main.cpp:141] 80Note: @0:00:05.883 in thread 4276 81Note: instruction: cmp 0xffffffc8(%ebp) $0x00000000 82 83Error #10: UNINITIALIZED READ: reading 0x04bbe070-0x04bbe074 4 byte(s) 84# 0 Tilemap::Get [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:106] 85# 1 Tilemap::createTilemap [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:40] 86# 2 std::_Invoker_pmf_pointer::_Call<> [d:\visual studio 2015\vc\include\type_traits:1373] 87# 3 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 88# 4 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1508] 89# 5 std::_Call_binder<> [d:\visual studio 2015\vc\include\functional:793] 90# 6 std::_Binder<>::operator()<> [d:\visual studio 2015\vc\include\functional:849] 91# 7 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 92# 8 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 93# 9 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 94#10 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 95#11 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 96#12 std::_Packaged_state<>::_Call_immediate [d:\visual studio 2015\vc\include\future:747] 97#13 <lambda_11ab3229cd29abcfc1db3f9148c7b3cc>::operator() [d:\visual studio 2015\vc\include\future:906] 98#14 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 99#15 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 100#16 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 101#17 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 102#18 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 103#19 <lambda_975747a413c1de54cd5be27432cdf231>::operator() [d:\visual studio 2015\vc\include\ppltasks.h:2308] 104Note: @0:00:07.309 in thread 4176 105Note: instruction: cmp 0x08(%ebp) $0x00000000 106 107Error #11: UNINITIALIZED READ: reading 0x04bbe070-0x04bbe074 4 byte(s) 108# 0 Tilemap::Get [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:106] 109# 1 Tilemap::createTilemap [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:41] 110# 2 std::_Invoker_pmf_pointer::_Call<> [d:\visual studio 2015\vc\include\type_traits:1373] 111# 3 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 112# 4 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1508] 113# 5 std::_Call_binder<> [d:\visual studio 2015\vc\include\functional:793] 114# 6 std::_Binder<>::operator()<> [d:\visual studio 2015\vc\include\functional:849] 115# 7 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 116# 8 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 117# 9 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 118#10 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 119#11 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 120#12 std::_Packaged_state<>::_Call_immediate [d:\visual studio 2015\vc\include\future:747] 121#13 <lambda_11ab3229cd29abcfc1db3f9148c7b3cc>::operator() [d:\visual studio 2015\vc\include\future:906] 122#14 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 123#15 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 124#16 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 125#17 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 126#18 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 127#19 <lambda_975747a413c1de54cd5be27432cdf231>::operator() [d:\visual studio 2015\vc\include\ppltasks.h:2308] 128Note: @0:00:07.314 in thread 4176 129Note: instruction: cmp 0x08(%ebp) $0x00000000 130 131Error #12: UNINITIALIZED READ: reading 0x04bbe070-0x04bbe074 4 byte(s) 132# 0 Tilemap::Get [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:106] 133# 1 Tilemap::createTilemap [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:42] 134# 2 std::_Invoker_pmf_pointer::_Call<> [d:\visual studio 2015\vc\include\type_traits:1373] 135# 3 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 136# 4 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1508] 137# 5 std::_Call_binder<> [d:\visual studio 2015\vc\include\functional:793] 138# 6 std::_Binder<>::operator()<> [d:\visual studio 2015\vc\include\functional:849] 139# 7 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 140# 8 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 141# 9 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 142#10 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 143#11 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 144#12 std::_Packaged_state<>::_Call_immediate [d:\visual studio 2015\vc\include\future:747] 145#13 <lambda_11ab3229cd29abcfc1db3f9148c7b3cc>::operator() [d:\visual studio 2015\vc\include\future:906] 146#14 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 147#15 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 148#16 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 149#17 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 150#18 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 151#19 <lambda_975747a413c1de54cd5be27432cdf231>::operator() [d:\visual studio 2015\vc\include\ppltasks.h:2308] 152Note: @0:00:07.318 in thread 4176 153Note: instruction: cmp 0x08(%ebp) $0x00000000 154 155Error #13: UNINITIALIZED READ: reading 0x04bbe070-0x04bbe074 4 byte(s) 156# 0 Tilemap::Get [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:106] 157# 1 Tilemap::createTilemap [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:43] 158# 2 std::_Invoker_pmf_pointer::_Call<> [d:\visual studio 2015\vc\include\type_traits:1373] 159# 3 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 160# 4 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1508] 161# 5 std::_Call_binder<> [d:\visual studio 2015\vc\include\functional:793] 162# 6 std::_Binder<>::operator()<> [d:\visual studio 2015\vc\include\functional:849] 163# 7 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 164# 8 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 165# 9 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 166#10 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 167#11 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 168#12 std::_Packaged_state<>::_Call_immediate [d:\visual studio 2015\vc\include\future:747] 169#13 <lambda_11ab3229cd29abcfc1db3f9148c7b3cc>::operator() [d:\visual studio 2015\vc\include\future:906] 170#14 std::_Invoker_functor::_Call<> [d:\visual studio 2015\vc\include\type_traits:1408] 171#15 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 172#16 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1494] 173#17 std::_Func_impl<>::_Do_call [d:\visual studio 2015\vc\include\functional:209] 174#18 std::_Func_class<>::operator() [d:\visual studio 2015\vc\include\functional:275] 175#19 <lambda_975747a413c1de54cd5be27432cdf231>::operator() [d:\visual studio 2015\vc\include\ppltasks.h:2308] 176Note: @0:00:07.322 in thread 4176 177Note: instruction: cmp 0x08(%ebp) $0x00000000 178 179Error #14: POSSIBLE LEAK 912 direct bytes 0x031137a8-0x03113b38 + 16343 indirect bytes 180# 0 replace_realloc [d:\drmemory_package\common\alloc_replace.c:2469] 181# 1 lua5.3.0.dll!lua_xmove +0x342 (0x72372be3 <lua5.3.0.dll+0x2be3>) 182# 2 lua5.3.0.dll!lua_newstate +0x15 (0x72386736 <lua5.3.0.dll+0x16736>) 183# 3 lua5.3.0.dll!luaL_newstate +0xc (0x7237398d <lua5.3.0.dll+0x398d>) 184# 4 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76ea7c04 <KERNEL32.dll+0x17c04>) 185 186Error #15: LEAK 472 direct bytes 0x03113eb8-0x03114090 + 0 indirect bytes 187# 0 replace_calloc [d:\drmemory_package\common\alloc_replace.c:2417] 188# 1 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x6f7bd (0x6ce62140 <allegro-5.0.10-monolith-md-debug+0x72140>) 189# 2 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x151fd4 (0x6cf44957 <allegro-5.0.10-monolith-md-debug+0x154957>) 190# 3 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6ceb60f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 191# 4 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6cf5ac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 192# 5 MSVCR110D.dll!beginthreadex +0x1a0 (0x6cb2e001 <MSVCR110D.dll+0x5e001>) 193# 6 MSVCR110D.dll!endthreadex +0x170 (0x6cb2e1d1 <MSVCR110D.dll+0x5e1d1>) 194# 7 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76ea7c04 <KERNEL32.dll+0x17c04>) 195 196Error #16: POSSIBLE LEAK 256 direct bytes 0x0316c940-0x0316ca40 + 1902 indirect bytes 197# 0 replace_realloc [d:\drmemory_package\common\alloc_replace.c:2469] 198# 1 lua5.3.0.dll!lua_xmove +0x342 (0x72372be3 <lua5.3.0.dll+0x2be3>) 199# 2 lua5.3.0.dll!luaopen_math +0x177 (0x72380738 <lua5.3.0.dll+0x10738>) 200# 3 lua5.3.0.dll!luaopen_string +0x1f81 (0x7238b092 <lua5.3.0.dll+0x1b092>) 201# 4 lua5.3.0.dll!luaopen_string +0x1832 (0x7238a943 <lua5.3.0.dll+0x1a943>) 202# 5 lua5.3.0.dll!lua_createtable +0x48 (0x72371439 <lua5.3.0.dll+0x1439>) 203# 6 lua5.3.0.dll!luaopen_package +0x72 (0x72381033 <lua5.3.0.dll+0x11033>) 204# 7 lua5.3.0.dll!lua_setlocal +0x760 (0x72379761 <lua5.3.0.dll+0x9761>) 205# 8 lua5.3.0.dll!lua_setlocal +0x33b (0x7237933c <lua5.3.0.dll+0x933c>) 206# 9 lua5.3.0.dll!lua_callk +0x43 (0x72371224 <lua5.3.0.dll+0x1224>) 207#10 lua5.3.0.dll!luaL_requiref +0x98 (0x72373d29 <lua5.3.0.dll+0x3d29>) 208#11 lua5.3.0.dll!luaL_openlibs +0x2a (0x7237cacb <lua5.3.0.dll+0xcacb>) 209 210Error #17: POSSIBLE LEAK 256 direct bytes 0x0316f558-0x0316f658 + 3305 indirect bytes 211# 0 replace_realloc [d:\drmemory_package\common\alloc_replace.c:2469] 212# 1 lua5.3.0.dll!lua_xmove +0x342 (0x72372be3 <lua5.3.0.dll+0x2be3>) 213# 2 lua5.3.0.dll!luaopen_math +0x177 (0x72380738 <lua5.3.0.dll+0x10738>) 214# 3 lua5.3.0.dll!luaopen_string +0x1f81 (0x7238b092 <lua5.3.0.dll+0x1b092>) 215# 4 lua5.3.0.dll!luaopen_string +0x1832 (0x7238a943 <lua5.3.0.dll+0x1a943>) 216# 5 lua5.3.0.dll!luaopen_string +0x1e7e (0x7238af8f <lua5.3.0.dll+0x1af8f>) 217# 6 lua5.3.0.dll!luaopen_string +0x15fc (0x7238a70d <lua5.3.0.dll+0x1a70d>) 218# 7 lua5.3.0.dll!luaopen_utf8 +0x2f20 (0x723905f1 <lua5.3.0.dll+0x205f1>) 219# 8 lua5.3.0.dll!lua_setfield +0x41 (0x723721e2 <lua5.3.0.dll+0x21e2>) 220# 9 lua5.3.0.dll!luaopen_io +0xba (0x7237d8ab <lua5.3.0.dll+0xd8ab>) 221#10 lua5.3.0.dll!lua_setlocal +0x760 (0x72379761 <lua5.3.0.dll+0x9761>) 222#11 lua5.3.0.dll!lua_setlocal +0x33b (0x7237933c <lua5.3.0.dll+0x933c>) 223 224Error #18: POSSIBLE LEAK 512 direct bytes 0x0317f2f8-0x0317f4f8 + 285 indirect bytes 225# 0 replace_realloc [d:\drmemory_package\common\alloc_replace.c:2469] 226# 1 lua5.3.0.dll!lua_xmove +0x342 (0x72372be3 <lua5.3.0.dll+0x2be3>) 227# 2 lua5.3.0.dll!luaopen_math +0x177 (0x72380738 <lua5.3.0.dll+0x10738>) 228# 3 lua5.3.0.dll!luaopen_string +0x1f81 (0x7238b092 <lua5.3.0.dll+0x1b092>) 229# 4 lua5.3.0.dll!luaopen_string +0x1832 (0x7238a943 <lua5.3.0.dll+0x1a943>) 230# 5 lua5.3.0.dll!lua_createtable +0x48 (0x72371439 <lua5.3.0.dll+0x1439>) 231# 6 lua5.3.0.dll!luaopen_os +0x29 (0x72382c1a <lua5.3.0.dll+0x12c1a>) 232# 7 lua5.3.0.dll!lua_setlocal +0x760 (0x72379761 <lua5.3.0.dll+0x9761>) 233# 8 lua5.3.0.dll!lua_setlocal +0x33b (0x7237933c <lua5.3.0.dll+0x933c>) 234# 9 lua5.3.0.dll!lua_callk +0x43 (0x72371224 <lua5.3.0.dll+0x1224>) 235#10 lua5.3.0.dll!luaL_requiref +0x98 (0x72373d29 <lua5.3.0.dll+0x3d29>) 236#11 lua5.3.0.dll!luaL_openlibs +0x2a (0x7237cacb <lua5.3.0.dll+0xcacb>) 237 238Error #19: POSSIBLE LEAK 4135 direct bytes 0x03187ab8-0x03188adf + 0 indirect bytes 239# 0 replace_operator_new [d:\drmemory_package\common\alloc_replace.c:2613] 240# 1 std::_Allocate<> [d:\visual studio 2015\vc\include\xmemory0:75] 241# 2 std::allocator<>::allocate [d:\visual studio 2015\vc\include\xmemory0:645] 242# 3 std::_Wrap_alloc<>::allocate [d:\visual studio 2015\vc\include\xmemory0:900] 243# 4 std::_Wrap_alloc<>::allocate [d:\visual studio 2015\vc\include\xmemory0:900] 244# 5 std::vector<>::_Reallocate [d:\visual studio 2015\vc\include\vector:1621] 245# 6 std::vector<>::reserve [d:\visual studio 2015\vc\include\vector:1036] 246# 7 std::_Hash<>::_Init [d:\visual studio 2015\vc\include\xhash:860] 247# 8 std::_Hash<>::_Check_size [d:\visual studio 2015\vc\include\xhash:877] 248# 9 std::_Hash<>::_Insert<> [d:\visual studio 2015\vc\include\xhash:747] 249#10 std::_Hash<>::emplace<> [d:\visual studio 2015\vc\include\xhash:271] 250#11 std::unordered_map<>::operator[] [d:\visual studio 2015\vc\include\unordered_map:419] 251 252Error #20: POSSIBLE LEAK 721111 direct bytes 0x04cc0020-0x04d700f7 + 0 indirect bytes 253# 0 replace_operator_new [d:\drmemory_package\common\alloc_replace.c:2613] 254# 1 std::_Allocate<> [d:\visual studio 2015\vc\include\xmemory0:75] 255# 2 std::allocator<>::allocate [d:\visual studio 2015\vc\include\xmemory0:645] 256# 3 std::_Wrap_alloc<>::allocate [d:\visual studio 2015\vc\include\xmemory0:900] 257# 4 std::vector<>::_Reallocate [d:\visual studio 2015\vc\include\vector:1621] 258# 5 std::vector<>::_Reserve [d:\visual studio 2015\vc\include\vector:1650] 259# 6 std::vector<>::resize [d:\visual studio 2015\vc\include\vector:1137] 260# 7 Tilemap::createTilemap [c:\users\lex\documents\visual studio 2015\projects\isselborgh tycoon\isselborgh tycoon\tilemap.cpp:25] 261# 8 std::_Invoker_pmf_pointer::_Call<> [d:\visual studio 2015\vc\include\type_traits:1373] 262# 9 std::invoke<> [d:\visual studio 2015\vc\include\type_traits:1476] 263#10 std::_Invoke_ret<> [d:\visual studio 2015\vc\include\type_traits:1508] 264#11 std::_Call_binder<> [d:\visual studio 2015\vc\include\functional:793] 265 266Error #21: HANDLE LEAK: USER handle 0x01d60140 and 7 similar handle(s) were opened but not closed: 267# 0 system call NtUserCreateWindowEx 268# 1 USER32.dll!GetCapture +0x4e4 (0x757018e5 <USER32.dll+0x118e5>) 269# 2 USER32.dll!GetCapture +0x6a0 (0x75701aa1 <USER32.dll+0x11aa1>) 270# 3 USER32.dll!CreateWindowExA +0x36 (0x75703397 <USER32.dll+0x13397>) 271# 4 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x164947 (0x6cf572ca <allegro-5.0.10-monolith-md-debug+0x1672ca>) 272# 5 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x151efe (0x6cf44881 <allegro-5.0.10-monolith-md-debug+0x154881>) 273# 6 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x15257e (0x6cf44f01 <allegro-5.0.10-monolith-md-debug+0x154f01>) 274# 7 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6ceb60f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 275# 8 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6cf5ac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 276# 9 MSVCR110D.dll!beginthreadex +0x1a0 (0x6cb2e001 <MSVCR110D.dll+0x5e001>) 277#10 MSVCR110D.dll!endthreadex +0x170 (0x6cb2e1d1 <MSVCR110D.dll+0x5e1d1>) 278#11 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76ea7c04 <KERNEL32.dll+0x17c04>) 279Note: @0:00:10.862 in thread 4276 280Note: handles created with the same callstack are closed here: 281Note: # 0 system call NtUserDestroyWindow 282Note: # 1 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x165a12 (0x6cf58395 <allegro-5.0.10-monolith-md-debug+0x168395>) 283Note: # 2 USER32.dll!CallNextHookEx +0xb0 (0x756f8e71 <USER32.dll+0x8e71>) 284Note: # 3 USER32.dll!CallNextHookEx +0x310 (0x756f90d1 <USER32.dll+0x90d1>) 285Note: # 4 USER32.dll!CallNextHookEx +0x56b (0x756f932c <USER32.dll+0x932c>) 286Note: # 5 USER32.dll!CallNextHookEx +0x768 (0x756f9529 <USER32.dll+0x9529>) 287Note: # 6 ntdll.dll!KiUserCallbackDispatcher +0x35 (0x77ed07d6 <ntdll.dll+0x407d6>) 288Note: # 7 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x15286d (0x6cf451f0 <allegro-5.0.10-monolith-md-debug+0x1551f0>) 289Note: # 8 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0xc3776 (0x6ceb60f9 <allegro-5.0.10-monolith-md-debug+0xc60f9>) 290Note: # 9 allegro-5.0.10-monolith-md-debug!al_set_thread_should_stop+0x1682fa (0x6cf5ac7d <allegro-5.0.10-monolith-md-debug+0x16ac7d>) 291Note: #10 MSVCR110D.dll!beginthreadex +0x1a0 (0x6cb2e001 <MSVCR110D.dll+0x5e001>) 292Note: #11 MSVCR110D.dll!endthreadex +0x170 (0x6cb2e1d1 <MSVCR110D.dll+0x5e1d1>) 293Note: #12 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76ea7c04 <KERNEL32.dll+0x17c04>) 294 295=========================================================================== 296FINAL SUMMARY: 297 298DUPLICATE ERROR COUNTS: 299 Error # 10: 4 300 Error # 11: 4 301 Error # 12: 4 302 Error # 13: 4 303 Error # 14: 3 304 Error # 15: 8 305 Error # 21: 8 306 307SUPPRESSIONS USED: 308 309ERRORS FOUND: 310 0 unique, 0 total unaddressable access(es) 311 13 unique, 25 total uninitialized access(es) 312 0 unique, 0 total invalid heap argument(s) 313 0 unique, 0 total GDI usage error(s) 314 1 unique, 8 total handle leak(s) 315 0 unique, 0 total warning(s) 316 1 unique, 8 total, 3837 byte(s) of leak(s) 317 6 unique, 8 total, 777403 byte(s) of possible leak(s) 318ERRORS IGNORED: 319 77 potential error(s) (suspected false positives) 320 (details: C:\Users\Lex\AppData\Roaming\Dr. Memory\DrMemory-Isselborgh Tycoon.exe.6284.000\potential_errors.txt) 321 109 potential leak(s) (suspected false positives) 322 (details: C:\Users\Lex\AppData\Roaming\Dr. Memory\DrMemory-Isselborgh Tycoon.exe.6284.000\potential_errors.txt) 323 145 unique, 2007 total, 76300 byte(s) of still-reachable allocation(s) 324 (re-run with "-show_reachable" for details) 325Details: C:\Users\Lex\AppData\Roaming\Dr. Memory\DrMemory-Isselborgh Tycoon.exe.6284.000\results.txt

But I don't think those uninitialized reads are the problem, because this problem still occures when I completely comment out the loop (except for the al_wait_for_event(event_queue, &ev) ofcourse). And every uninitialized read it reports occures in the loop.

Is this more useful?

Thomas Fjellstrom

You may need to show some code. Uninitialized accesses are a sign you're doing something wrong. ALWAYS initialize your variables.

mijgame

Well, here is LuaScript::Execute for example:

#SelectExpand
1bool LuaScript::Execute() 2{ 3 if (luaL_loadfile(LuaState, resource.c_str())) 4 { 5Line 80 -> std::cout << "Lua script " << resource << ": file not found." << std::endl; 6 return false; 7 } 8 9 if (lua_pcall(LuaState, 0, 0, 0)) 10 { 11 LuaHelpers::StackDump(LuaState); 12 al_show_native_message_box(display->Get(), "Error", "Script failure", Stack::Get<string>(LuaState, Stack::Top).c_str(), nullptr, ALLEGRO_MESSAGEBOX_ERROR); 13 } 14 15 std::cout << "Lua -> Script " << resource << " loaded\n" << std::endl; 16 17 return true; 18}

Resource is an std::string, and if it was empty c_str() would zero-terminate it.

And FontManager::LoadFromList:

#SelectExpand
1void FontManager::LoadFromList(string list) 2{ 3 string location = "resources/lists/" + list + ".txt"; 4 5 auto lines = Filereader::ReadAndSplit(location, "|"); 6 7 for (vector<string> &line : lines) 8 { 9 fontNames[line[0]] = line[1]; 10 } 11 12Line 21 -> std::cout << "Font list loaded: " << list << "\nFonts loaded: " << lines.size() << "\n" << std::endl; 13}

Same story. Also, these functions have worked perfectly for a good while, and they haven't changed. That makes me believe that it does not cause the error.

And this is Game::Initialize:

#SelectExpand
1void Game::Initialize() 2{ 3 auto texScript = ScriptContainer->Insert("textures", new LuaScript("scripts/textures.lua")); 4 texScript->RegisterFunctions(TextureManager::LuaTextureFunctions); 5 texScript->Execute(); 6 7 MenuSystem->CreateMenus(); 8 GameWorld->Create(MAP_WIDTH, MAP_HEIGHT); 9}

This executes a Lua script in which textures names and locations are defined.
I have already checked for things like Lua stackoverflows, but that doesn't seem the be the issue either.

I'm using Allegro 5.0.10 with Windows 10 by the way (sorry for not mentioning that before).

Rodolfo Lam

Well... now that I remember, once I had a heap corruption error that only happened on Linux but not on Windows. What was more interesting with this error was that I could only reliably replicate it when the screen mode was any of the automatic full screen modes (full screen windowed not included).

Unfortunately lost access to the machine in which the error happened and was never able to pinpoint the exact cause for this strange situation...

Thomas Fjellstrom

It's possible your event_queue isn't valid or was corrupted.

Otherwise I really can't see any real error in what you're showing (but I didn't study your posted code in depth).

If it can be built on linux, I can take a look at it and see if i can find the issue.

mijgame

I ended up redownloading allegro, recompiling lua, and changing things around in main(). I don't know what did it in the end, but it works know. Weird stuff.

In any case, thanks a lot for helping! I really appreciate it :)

Thomas Fjellstrom

It could be a compiler version mismatch or some other thing. Or its still got memory corruption and your reordering of stuff is hiding it :(

Memory corruption is like that. You can change one little thing and hide it, or show a problem you had for ages that just didn't cause a crash before.

GullRaDriel

Sounds like an uninitialized pointer use or a bad malloc to me.

Thread #615638. Printed from Allegro.cc