Game Development Community

DLL Question

by Matt "Mr. Pig" Razza · in Technical Issues · 08/09/2006 (4:48 pm) · 1 replies

I've been playing with DLL's (as I never made one) lately. Before I'd copy the .h and .cpp file of the classes I use alot into my projects - I finally decided I needed a DLL.

I dumped all my classes in it, added the export line to them and built it. I then too one of my apps (that used a lot of those classes) and converted it to use the DLL. Built it, ran it, it worked fine. I woke up the next morning (I guess I must have changed something) because when I ran my app again - it crashed. Heres the error:

Windows has triggered a breakpoint in ServConv.exe.

This may be due to a corruption of the heap, and indicates a bug in ServConv.exe or any of the DLLs it has loaded.

The call stack pointed to a line inside the DLL where data was being written/read from a std::string. (The callstack changed slightly later on in the day - not sure why.)

ntdll.dll!7d61002d() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]	
 	ntdll.dll!7d681da1() 	
 	ntdll.dll!7d659cee() 	
 	ntdll.dll!7d642da9() 	
 	kernel32.dll!7d507e35() 	
>	msvcr80d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x005a3390)  Line 1963	C++
 	msvcr80d.dll!_free_dbg_nolock(void * pUserData=0x005a3390, int nBlockUse=1)  Line 1252 + 0x9 bytes	C++
 	msvcr80d.dll!_free_dbg(void * pUserData=0x005a3390, int nBlockUse=1)  Line 1194 + 0xd bytes	C++
 	msvcr80d.dll!operator delete(void * pUserData=0x005a3390)  Line 54 + 0x10 bytes	C++
 	msvcp80d.dll!std::allocator<char>::deallocate(char * _Ptr=0x005a3390, unsigned int __formal=48)  Line 147 + 0x9 bytes	C++
 	msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(bool _Built=true, unsigned int _Newsize=0)  Line 2048	C++
 	msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >()  Line 878	C++
 	mrStandard.dll!fileSys::setNewLine(std::basic_string<char,std::char_traits<char>,std::allocator<char> > text="===============================================")  Line 261 + 0x12 bytes	C++
 	ServConv.exe!processManager::processManager(std::basic_string<char,std::char_traits<char>,std::allocator<char> > logFile="processLog.txt")  Line 42	C++
 	ServConv.exe!'dynamic initializer for 'procMan''()  Line 16 + 0x43 bytes	C++
 	ServConv.exe!_initterm(void (void)* * pfbegin=0x004bf264, void (void)* * pfend=0x004bf3b8)  Line 855	C
 	ServConv.exe!_cinit(int initFloatingPrecision=1)  Line 293 + 0xf bytes	C
 	ServConv.exe!__tmainCRTStartup()  Line 301 + 0x7 bytes	C
 	ServConv.exe!mainCRTStartup()  Line 187	C
 	kernel32.dll!7d4e992a()

I resurched a little and came accross this:
http://www.gamedev.net/community/forums/topic.asp?topic_id=390427

I am using the Release Version of my DLL for the Release Build of my app (and the debug for the debug). The .lib I'm loading with the pargma call is the Release .lib but both the release build and the debug build crash with the same error.

Any ideas?

Note: I got the DLL to work without a problem in another one of my applications - but I can't find the difference.

Thanks.

#1
08/10/2006 (3:58 pm)
Ah, I think I found the problem. I have the Debug and Release dll's under the same name and I do not unload them (or load them manually) so they remain in memory (unless window's AlwaysUnloadDLL is set it to 1). So what happens is if I run a release build, then attempt to run a debug build it'll break any use of either debug/release dll's until I reboot (or unload the DLL).