Access Violation in Qt postEvent - c++

I have an application that is starting to throw fits at various points. It was written ages ago using one of the first versions of the Qt library. Love to update it but that's not in the cards yet. While testing a part of the app, I received an unexpected crash:
Unhandled exception at 0x00a220db in MyApp.exe:
0xC0000005: Access violation reading location 0x00000000.
The application code that I can see (the Qt lib source code is not available for debugging so it's just a disassembly).
MyEvent myEvent = new MyEvent(str1, int, str2);
QApplication::postEvent(parent(), myEvent);
Call stack at the affected area:
MyApp.exe!QGList::append() + 0x6b bytes
MyApp.exe!QList<QPostEvent>::append() + 0x2f bytes
MyApp.exe!QApplication::postEvent() + 0x55a bytes
> MyApp.exe!SomeClass::writeTestName(const char * format=0x00f6c2b8, ...) Line 386 + 0x15 bytes
If I examine myEvent and parent(), both appear to be valid. What is the postEvent method adding my event to and, assuming it's a Qt internal, which it appears to be, why would it fail - is there some initialization that needs to be done that the original programmer might have missed?

Related

ID3D12GraphicsCommandList::ClearUnorderedAccessViewFloat Access violation reading location

ID3D12GraphicsCommandList& commandList = *com_ptr;
FLOAT values[4] = { 1,1,1,1 };
commandList.ClearUnorderedAccessViewFloat(m_gpuUavHandle, m_cpuUavHandle, m_resource.get(), values, 0, nullptr);
I'm getting the following runtime error:
Access violation reading location 0x0000000000000140
However, m_cpuUavHandle.ptr has value 326 which is only 6 bytes after the location of the access violation 320 (=140 in hexidecimal).
Since in Direct3d12 you manually calculate the handle address, it seems that there is room for something to go wrong
m_cpuUavHandle = CD3DX12_CPU_DESCRIPTOR_HANDLE(m_descriptorHeap.get()->GetCPUDescriptorHandleForHeapStart(), offset, m_cbvSrvUavDescriptorSize);
Edit:
I succeeded reproducing this in the DirectX 12 samples (and uploaded it to github) and this time got a debug message
D3D12 ERROR: ID3D12CommandList::ClearUnorderedAccessViewFloat: Specified descriptor handle ptr=0x0000000000000021 points to a descriptor heap type that is CPU write only, so reading it is invalid. UnorderedAccessViewCPUHandle is the issue. [ EXECUTION ERROR #646: INVALID_DESCRIPTOR_HANDLE]
Now m_cpuUavHandle.ptr=33 and the location of the access violation is at 32 (0x0000000000000020 in hexidecimal).
In my main project I think the exception is hit before the debug message is printed due to threading issues.
Now in my main project I'm getting
Access violation reading location 0x0000000000000000.
which is still six bytes before m_cpuUavHandle.ptr = 6, so I'm not sure if this is right
mateeeeee solved this in the comments. The docs specify that the cpu descriptor must refer to a non-shader visible heap (one created with D3D12_DESCRIPTOR_HEAP_FLAG_NONE).
For me the solution is to just have two identical CBV_SRV_UAV heaps one created with D3D12_DESCRIPTOR_HEAP_DESC::Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE for calling ClearUnorderedAccessViewFloat and the other created with D3D12_DESCRIPTOR_HEAP_DESC::Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE for everything else.
It is important to note that the cpu descriptor and gpu descriptor arguments for ClearUnorderedAccessViewFloat must come from different heaps.

VisualC++ 2010 Is there a way to find out more details surrounding unhandled exception error

A windows application I am working on contains the following code:
if (_camStar->GetSortedContainersFromOpsView("CAD", false, containers, errorMessage)) {
error = "";
if (!containers.empty())
{
desc = QString::fromStdString(containers[0]->masterProductDescription);
prodname = QString::fromStdString(containers[0]->productName).trimmed();
res = QString::fromStdString(containers[0]->ctnrName);
}
}
else
{
error = QString::fromStdString(errorMessage);
}
_camStar is a variable from an external header file to which I am initializing here via:
_camStar = new CamstarInterface(host, port, username, password, workstation);
CamstarInterface is an interface that's declared in that same header file. When I run the program in Debug mode, I am presented with:
Unhandled Exception at 0xx5c84337d (msvcp100d.dll) in initializer.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
and it breaks in xutility (I believe its used by Qt) in the function Orphan_all(). When I run the program in Release mode, everything works fine.
How would I go about digging into the exception to see what exactly it doesn't like?
EDIT: The xutility file is shown when I have a try/catch surrounding the code above and is opened when I return the QString res variable. Otherwise I see the following unhandled exception on the GetSortedContainersFromOpsView line:
Unhandled Exception at 0x000007fefce7a06d in initializer.exe: 0xC0000005: Access violation writing location 0x00000000004ffff8.
No other file is opened. The stack trace looks like so:
initializer!initializer::GetNextImplant(QString& error) Line 347 + 0x5e bytes
initializer!initializer::Process() Line 298 + 0x17 bytes
initializer!initializer::Start() Line 169
initializer!main(int argc, char**argv) Line 18
initializer!WinMain() line 131 + 0x16 bytes
initializer!__tmainCRTStartup() line 547 + 0x42 bytes
initializer!WinMainCRTStartup() Line 371
At line 347 is the GetSortedContainersFromOpsView call. What should I do? It doesn't really seem to give me much.
The issue was indeed related to one of the dependencies. One of the dependencies has invalid references due to a .NET 4.5/Visual Studio 2010 issue. Removing and re-adding all of those references in the dependency project, and rebuilding the library fixed the issue.

static lib call error: Exception: "A null reference pointer was passed to the stub." (using winsock2 Win32)

I created a windows-console application that works fine but trying to use Winsock2 (Ws2_32.lib) in another static-library (as part of a larger project) throws an exception.
The code compiles fine and the exe runs all is well, calls to WSAStartup() and gethostbyname() work as expected but then calling gethostbyname()
causes :
First-chance exception at 0x76e1c41f in TestApp.exe: 0x000006F4: A null reference pointer was passed to the stub.
which leads to:
First-chance exception at 0x7505cd99 (rpcrt4.dll) in TestApp.exe: 0xC0020043: An internal error occurred in RPC.
Ive double checked the calling code is the same and checked that the correct versions of the *.h *.dll and *.lib are being used by the linker - as far as i can tell they are.
I've compared the project settings for the two apps and cant see anything out of the ordinary.
Ive also made sure that all the libraries in the Project are using the same Character-Set.
[EDIT : chages after discovering the difference in the two apps is just the debugger exceptions being turned on or not ]
I can continue past the exceptions and the code appears to run, but I no longer have valid debugging symbols in the function. It isnt a crash but of course id rather not have the exceptions every time I call the function - I can obviously turn the exception-breaks off but aren't they there to tell me something is wrong ?
I am currently trying to get the up-to-date symbols for the ws2_32.lib and other modules from the MSDN symbol server / SymChk.exe
[EDIT 2 - finally got symbols for the stack]
> rpcrt4.dll!_NdrClientCall2() + 0x301 bytes
FWPUCLNT.DLL!_FwppProxyEngineOpen#24() + 0x19 bytes
FWPUCLNT.DLL!_FwppSessionCreate#20() + 0xd1 bytes
FWPUCLNT.DLL!_FwpmEngineOpen0#20() + 0x29 bytes
FWPUCLNT.DLL!_FwpIsNameCacheEnabledForProcess#4() + 0x7778 bytes
FWPUCLNT.DLL!_FwpmProcessNameResolutionEvent0#16() + 0x74 bytes
FWPUCLNT.DLL!_NamespaceCallout#12() + 0x72 bytes
ws2_32.dll!PrepareNamespaceCalloutBlob() + 0x153 bytes
ws2_32.dll!getxyDataEnt() + 0x74a7 bytes
ws2_32.dll!_gethostbyname#4() + 0xe7 bytes
I was getting this exception "0x000006F4: A null reference pointer was passed to the stub."
Turns out disabling my 3rd party firewall stopped the exception being thrown. Perhaps the firewall is intercepting the request and messing something up.
Might be worth a try for you :)

std::string crashing while iterating on mySQL connector query results

I'm trying to get a std::string from my database using mysql connexion
Here is the simple code:
sql::Statement *stmt = con->createStatement();
sql::ResultSet *res = stmt->executeQuery("SELECT * FROM test.new_table");
while (res->next()) {
std::string somestring = res->getString("idnew_table");
} //crashes here
delete res;
delete stmt;
So, the executeQuery is fine, I enter the loop, and if I break, the expected results are in somestring. After the somestring declaration, I step foward to the end of the loop, and it crashes before the next iteration!
Here is the call stack:
> msvcp100d.dll!std::_Lockit::_Lockit(int kind) Line 64 + 0x14 bytes C++
msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 200 C++
CM.dll!std::_String_val<char,std::allocator<char> >::~_String_val<char,std::allocator<char> >() Line 478 + 0xb bytes C++
CM.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 755 + 0xf bytes C++
CM.dll!DAL::GetInfo() Line 45 + 0xc bytes C++
Output:
First-chance exception at 0x1038ad4a (msvcp100d.dll) in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
First-chance exception at 0x76f5016e in CMLauncher.exe: 0x00000000: The operation completed successfully.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0x00000000: The operation completed successfully.
So it looks like I have some uninitialized memory somewhere in the C++ runtime lib...
It look like it's crashing in the std::string destructor, which kind of makes sense because it crashes when the scope of the string is done...
My best guess is that libmysql is using an older version of the C++ runtime (say msvcp90d.dll) and that it's clashing with the new one... does that even make sense?
I'm under windows 7, using mySQL Server 5.5, VS2010 Pro. all in 32bits. thx! I'll be happy to post any mroe information that is needed.
Edit: Before anyone else reads DumbCoders comment:
MySQL Connector example
The documentation specifies that both the statement and the resultSet have to be deleted.
This problem seems just like yours here.

Program crashes with 0xC000000D and no exceptions - how do I debug it?

I have a Visual C++ 9 Win32 application that uses a third-party library. When a function from that library is called with a certain set of parameters the program crashes with "exception code 0xC000000D".
I tried to attach Visual Studio debugger - no exceptions are thrown (neither C++ nor structured like access violations) and terminate() is not called either. Still the program just ends silently.
How does it happen that the program just ends abnormally but without stopping in the debugger? How can I localize the problem?
That's STATUS_INVALID_PARAMETER, use WinDbg to track down who threw it (i.e. attach WinDbg, sxe eh then g.
Other answers and comments to the question helped a lot. Here's what I did.
I notices that if I run the program under Visual Studio debugger it just ends silently, but if I run it without debugger it crashes with a message box (usual Windows message box saying that I lost my unsaved data and everyone is sooo sorry).
So I started the program wihtout debugger, let it crash and then - while the message box was still there - attached the debugger and hit "Break". Here's the call stack:
ntdll.dll!_KiFastSystemCallRet#0()
ntdll.dll!_ZwWaitForMultipleObjects#20() + 0xc bytes
kernel32.dll!_WaitForMultipleObjectsEx#20() - 0x48 bytes
kernel32.dll!_WaitForMultipleObjects#16() + 0x18 bytes
faultrep.dll!StartDWException() + 0x5df bytes
faultrep.dll!ReportFault() + 0x533 bytes
kernel32.dll!_UnhandledExceptionFilter#4() + 0x55c bytes
//SomeThirdPartyLibraryFunctionAddress
//SomeThirdPartyLibraryFunctionAddress
//SomeThirdPartyLibraryFunctionAddress
//SomeThirdPartyLibraryFunctionAddress
//OurCodeInvokingThirdPartyLibraryCode
so obviously that's some problem inside the trird-party library. According to MSDN, UnhandledExceptionFilter() is called in fatal situations and clearly the call is done because of some problem in the library code. So we'll try to work the problem out with the library vendor first.
If you don't have source and debugging information for your 3rd party library, you will not be able to step into it with the debugger. As I see it, your choices are;
Put together a simple test case illustrating the crash and send it onto the library developer
Wrap that library function in your own code that checks for illegal parameters and throw an exception / return an error code when they are passed by your own application
Rewrite the parts of the library that do not work or use an alternative
Very difficult to fix code that is provided as object only
Edit You might also be able to exit more gracefully using __try __finally around your main message loop, something like
int CMyApp::Run()
{
__try
{
int i = CWinApp::Run();
m_Exitok = MAGIC_EXIT_NO;
return i;
}
__finally
{
if (m_Exitok != MAGIC_EXIT_NO)
FaultHandler();
}
}