🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Crash when calling AddScriptSection

Started by
0 comments, last by WitchLord 18 years, 6 months ago
Hi all, It's me agin. With another problem. When I try to add a script section the application crashes and gives the folliwing error message: "Unhandled exception at 0x004ce06b in TestApp.exe: 0xC0000005: Access violation reading location 0x00000044." When I run the debugger the Disassembly looks like (I've marked the line the debugger complains about): " ... ... ... asRet = asEnginePtr->AddScriptSection(script->m_module.c_str(), script->m_name.c_str(), script->m_scriptCode.c_str(), script->m_scriptLength, 0, false); 004CE035 mov esi,esp 004CE037 push 0 004CE039 push 0 004CE03B mov eax,dword ptr [script] 004CE03E mov ecx,dword ptr [eax+1Ch] 004CE041 push ecx 004CE042 mov ecx,dword ptr [script] 004CE045 call std::basic_string<char,std::char_traits<char>,std::allocator<char> >::c_str (4964F4h) 004CE04A push eax 004CE04B mov ecx,dword ptr [script] 004CE04E add ecx,20h 004CE051 call std::basic_string<char,std::char_traits<char>,std::allocator<char> >::c_str (4964F4h) 004CE056 push eax 004CE057 mov ecx,dword ptr [script] 004CE05A add ecx,3Ch 004CE05D call std::basic_string<char,std::char_traits<char>,std::allocator<char> >::c_str (4964F4h) 004CE062 push eax 004CE063 mov edx,dword ptr [asEnginePtr] 004CE066 mov eax,dword ptr [edx] 004CE068 mov ecx,dword ptr [asEnginePtr] 004CE06B call dword ptr [eax+44h] <----------------- THIS IS THE LINE THE DEBUGGER COMPLAINS ABOUT 004CE06E cmp esi,esp 004CE070 call @ILT+14670(__RTC_CheckEsp) (497953h) 004CE075 mov dword ptr [asRet],eax assert( asRet >= 0 ); ... ... ..." And the debugger points to the line I've marked above. I've checked my code for NULL pointers but all pointers are valid. The script variable in the AddScriptSection above i a class callde CScript and it is responsible for loading the script from an ordianry text file as follows: HRESULT CScript::Load(const char *name, const char* module) { HRESULT hRet = S_OK; // Set the name m_name = string(name); m_fullName = string(MEDIA_PATH) + string(name); // Set the module m_module = string(module); // Load the script file FILE *f = fopen(m_fullName.c_str(), "rb"); if (f != NULL){ // Get the length of the script file fseek(f, 0, SEEK_END); m_scriptLength = ftell(f); fseek(f, 0, SEEK_SET); // Copy the file data m_scriptCode.resize(m_scriptLength); if (fread(&m_scriptCode[0], m_scriptLength, 1, f) == 0) { G_TRACE_1("CScript::Load : Failed to load script %s\n", m_fullName.c_str()); hRet = E_FAIL; } } else { G_TRACE_1("CScript::Load : Failed to open script %s\n", m_fullName.c_str()); hRet = E_FAIL; } // Close the file fclose(f); return hRet; } Before I call the AddScriptSection I've validated the script and asEnginePtr variable and checked all parameters and they are all valid. I also print out the actual script->m_scriptCode.c_str() and it gives the contents of the script text file. I simply have no ideas as to what is wrong. Any ideas anyone? Best Regards, Risto Hietanen
Advertisement
Your code for loading the script looks just fine.

You're application crashes just on the moment when the virtual method AddScriptSection() is called, all the parameters have been successfully evaluated and pushed on the stack.

asEnginePtr may not be null, but it's vtable certainly is. The application is trying to read the function address for AddScriptSection from memory location 0x00000044, which tells me that it is using a vtable pointer = 0. Examine the first DWORD in the engine object that asEnginePtr is pointing to, you'll see that it is null, which is an invalid value.

The most likely cause of this is that somewhere in your code you're writing outside allocated memory, which overwrites the first bytes in the engine object. I suggest you set a break point for when the first bytes in asEnginePtr changes. This will allow you to catch the exact moment where the vtable is set to 0.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement