Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Bad access in virtual methods (iOS ARM)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Cordan   Members   -  Reputation: 126

Like
0Likes
Like

Posted 28 September 2012 - 02:01 PM

I getting EXC_BAD_ACCESS in virtual methods when i run program on iPad.
It happens only if method returns registered data type and if method have virtual definition in base class.

My code:

[source lang="cpp"]virtual my_type Base::method() = 0;...my_type Derived::method(){ ... this->field = 10; // EXC_BAD_ACCESS ...}[/source]

If i replace code above with:
[source lang="cpp"]virtual void Base::method(my_type &res) = 0;...void Derived::method(my_type &res){ ... this->field = 10; // OK ...}[/source]
problem will disappear.

I have this problem only on ios device. i've tested my code on windows, osx and iphone simulator - all is ok. If i replace 'my_type' to 'int' all is ok as well.

It looks like calling of virtual methods with wrong object.

So, what it can be?

ps: as version - 2.25.0

Edited by Cordan, 28 September 2012 - 02:07 PM.


Sponsor:

#2 Jake Albano   Members   -  Reputation: 631

Like
0Likes
Like

Posted 29 September 2012 - 01:42 PM

Can you show the code where you register my_type with the script engine, as well as the registration code for this method?

#3 Cordan   Members   -  Reputation: 126

Like
0Likes
Like

Posted 30 September 2012 - 04:51 AM

Of course.


Method:
[source lang="cpp"]int r = engine->RegisterObjectMethod("Derived", "my_type method()",asSMethodPtr<sizeof(void (Derived::*)())>::Convert(&Derived::method),asCALL_THISCALL);assert(r >= 0);[/source]

Type:
[source lang="cpp"]int r = engine->RegisterObjectType("my_type", sizeof(my_type), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);assert(r >= 0);r = engine->RegisterObjectBehaviour("my_type", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(__construct<my_type>), asCALL_CDECL_OBJLAST);assert(r >= 0);r = engine->RegisterObjectBehaviour("my_type", asBEHAVE_CONSTRUCT, "void f(const my_type &in)", asFUNCTION(__construct_copy<my_type>),asCALL_CDECL_OBJLAST); assert(r >= 0);r = engine->RegisterObjectBehaviour("my_type", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(__destruct<my_type>), asCALL_CDECL_OBJLAST);assert(r >= 0);r = engine->RegisterObjectMethod("my_type", "my_type& opAssign(my_type &in)", asSMethodPtr<sizeof(my_type& (my_type::*)(const my_type&))>::Convert((my_type& (my_type::*)(const my_type&))(&my_type::operator=)), asCALL_THISCALL); assert(r >= 0);[/source]

#4 Jake Albano   Members   -  Reputation: 631

Like
0Likes
Like

Posted 30 September 2012 - 08:39 AM

I'm not familiar with asSMethodPtr, so I don't know if you have a specific reason for using it, but why not use the asMETHODPR macro?

r = engine->RegisterObjectMethod("my_type", "my_type& opAssign(my_type &in)", asMETHODPR(my_type, operator=, (const my_type&), my_type&), asCALL_THISCALL);

It's probably not the problem, but pointers to member functions are tricky and the macros do some extra magic under the hood.

#5 Cordan   Members   -  Reputation: 126

Like
0Likes
Like

Posted 30 September 2012 - 01:17 PM

It not helps. asMETHODPR is wrapper around asSMethodPtr.
I'm still getting crashes when use virtual and pure-virtual methods.

I guess it is memory corruption in arm implementation of angel script. After call of any virtual method which returns my type crash occurs. It occurs either in method itself or further in code.

Edited by Cordan, 30 September 2012 - 01:18 PM.


#6 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 03 October 2012 - 06:50 PM

I haven't done any iOS development on my own so I can't test this, but it looks to be a problem in the AngelScript code when handling the hidden address for returning objects by value.

I'll review the code to see if I can spot the error. I may need some help from you to run some tests for me in order to have this fixed.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#7 Cordan   Members   -  Reputation: 126

Like
0Likes
Like

Posted 04 October 2012 - 08:08 AM

I'll review the code to see if I can spot the error. I may need some help from you to run some tests for me in order to have this fixed.

I sent PM to you.

#8 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
1Likes
Like

Posted 18 October 2012 - 07:26 PM

Alright. I'm sorry for taking so long to start looking into this problem, but I've had a quite chaotic couple of weeks at work since I got back from work. What little time that remained I spent on fixing the logical bugs in AngelScript.

After reviewing the code I believe the problem is caused by an inverted condition on line 204 in as_callfunc_arm.cpp. I believe that line should should be #ifdef __GNUC__, i.e:

case ICC_VIRTUAL_THISCALL_RETURNINMEM:
  // Get virtual function table from the object pointer
  vftable = *(asFUNCTION_t**)obj;
#ifdef __GNUC__   /// <-- change this to ifdef, so that R0 is populated with retPointer
  retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj);
#else
  retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj, (asDWORD)retPointer);
#endif
  break;

Please let me know if this change corrects the problem, and I'll check in the modification.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#9 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 19 October 2012 - 05:42 PM

Well, I'm so sure the fix is correct that I checked in the change in revision 1440 anyway. Please let me know if I was wrong and I'll undo the change.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#10 Cordan   Members   -  Reputation: 126

Like
0Likes
Like

Posted 20 October 2012 - 01:01 PM

Yes, everything works now. Huge thanks! :)

#11 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 20 October 2012 - 08:10 PM

Thanks for confirming that it's working properly.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS