monkey2 icon indicating copy to clipboard operation
monkey2 copied to clipboard

Android (Threads vs None) Release vs Debug differences #BUG

Open XANOZOID opened this issue 7 years ago • 6 comments

Bug Details

Develop Branch (Jul 26, 2018) Mx2cc version 1.1.15 MSVC x64 - Updated Bugged Export: Android Release W/ Threads

Synopsis:

My project is about 1,569 LOC. It works perfectly fine and very smooth in the single threaded Android release. With threaded support enabled, it appears that all methods inside of a stack of object-stored functions are iterated through, but only the last function is actually executed. This is strange behavior because on Debug mode, with threads enabled, it works like normal (or appears too)!

Possible Code To Test

Even though my project is big I'm confident to say that this code provided should be testable. Otherwise I can send you my project to test with. But I recommend comparing the results of the following code between (1)Android Single Threaded Release, (2)Android Release Multithreaded Enabled, and (3)Android Debug Multi-threaded Enabled. (2) should not work.

#Import "<std>"

Using std..

Class Holder 

	Field item:Void(ULong)
	Method New( item_:Void(ULong) )
		item=item_
	End
	
End

Function Testfunc( val:ULong )
	Print "<external function> TestFunc val: " + val
End

Class TestOther

	Method MyMethod( val:ULong )
		Print "<other object method> MyMethod val: " + val
	End
	
End

Class Test
	
	Field holders:Stack<Holder>
	Method New()
		holders=New Stack<Holder>
		
		holders.Add(New Holder( Lambda( val:ULong )
			Print "<lambda> anonymous val: " + val
		End ) )
		
		holders.Add( New Holder( CallMe ) )
		
		holders.Add( New Holder( Testfunc ) )
		
		Local obj:=New TestOther
		holders.Add( New Holder( obj.MyMethod ) )
		
	End
	
	Method CallMe( val:ULong )
		Print "<method> CallMe Val: " + val
	End
	
	Method Run()
		
		Print ": START LOOP :~n"
		' Inside a loop
		Local i:=0
		For Local holder:=Eachin holders
			holder.item( 1000 + RndULong() Mod 200 )
			Print "Loop: " + i
			i +=1
		Next
		
		Print "~n: END LOOP :~n~n~nStarting Normal~n"
		
		' Normal Calls
		CallMe( RndULong() Mod 200  )
		Testfunc( RndULong() Mod 200 )
		Local obj:=New TestOther
		obj.MyMethod( RndULong() Mod 200  )
		
	End
End

Function Main()
	Local test:=New Test
	test.Run()
End
  • Not tested on Android Versions since my computer will take forever to compile all the stuff all over again for the tests, sorry :(!

XANOZOID avatar Jul 29 '18 03:07 XANOZOID

Expected Pass

should output:

: START LOOP :

<lambda> anonymous val: 1060
Loop: 0
<method> CallMe Val: 1180
Loop: 1
<external function> TestFunc val: 1024
Loop: 2
<other object method> MyMethod val: 1184
Loop: 3

: ENDING LOOP :


Starting Normal
<method> CallMe Val: 36
<external function> TestFunc val: 111
<other object method> MyMethod val: 34

Expected Fail

(Android Release w/ Threads) If it fails, like I have seen in my game, it should (probably?) be:

: START LOOP :

Loop: 0
Loop: 1
Loop: 2
<other object method> MyMethod val: 1184
Loop: 3

: ENDING LOOP :


Starting Normal
<method> CallMe Val: 36
<external function> TestFunc val: 111
<other object method> MyMethod val: 34

XANOZOID avatar Jul 29 '18 04:07 XANOZOID

It's a very convoluted example, is there no way you can simplify it a bit?

blitz-research avatar Jul 29 '18 21:07 blitz-research

At least rip out the 'normal calls bit that aren't failing? Also any other stuff that isn't failing, and I don't really need 3 failure cases, just one (assuming it's the same bug) the rest is just noise.

blitz-research avatar Jul 29 '18 21:07 blitz-research

I cannot currently reproduce the problem.

I have tried both debug and release threaded mode and am running on the x86 emulator with api 25. NDK version is 17.1.4828580

I get the same output in both cases, ie: the correct 'magic numbers' shown above.

blitz-research avatar Jul 29 '18 23:07 blitz-research

Hey, I've found a bug in functions, not sure if it's this one though. Fix should be up soon, will let you know...

On Sun, Jul 29, 2018 at 4:02 PM Abe King [email protected] wrote:

Expected Pass

should output:

: START LOOP :

anonymous val: 1060 Loop: 0 CallMe Val: 1180 Loop: 1 TestFunc val: 1024 Loop: 2 MyMethod val: 1184 Loop: 3

: ENDING LOOP :

Starting Normal CallMe Val: 36 TestFunc val: 111 MyMethod val: 34

Expected Fail

(Android Release w/ Threads) If it fails, like I have seen in my game, it should (probably?) be:

: START LOOP :

Loop: 0 Loop: 1 Loop: 2 MyMethod val: 1184 Loop: 3

: ENDING LOOP :

Starting Normal CallMe Val: 36 TestFunc val: 111 MyMethod val: 34

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/blitz-research/monkey2/issues/411#issuecomment-408650311, or mute the thread https://github.com/notifications/unsubscribe-auth/ADU3QjZcfKYRG-kVwRAoee1NxW2GG8Nlks5uLTPCgaJpZM4VlRl9 .

blitz-research avatar Jul 30 '18 06:07 blitz-research

I can confirm there is still a bug in version 2018.07rc2. This behavior occures in Android export (in my case Release mode) and only if compiled with MX2_THREADS=1. But unfortunately I have also no simple code to reproduce.

Mac767 avatar Aug 13 '18 20:08 Mac767