Recent

Author Topic: A LAMW Bug?  (Read 6344 times)

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
A LAMW Bug?
« on: January 18, 2018, 06:33:41 pm »
Can someone please tell me it is a bug in LAMW or something wrong in my code?

I was writing a game using LAMW. Everything was okay, but until I found if I press the the jCanvasES2 component repeatedly very fast then my app will crash. It is 100% reproducible.

Here is the code after removing all the unnecessary things:
Code: Pascal  [Select]
  1. {Hint: save all files to location: /home/handoko/Desktop/MicroWorld/jni }
  2. unit unit1;
  3.  
  4. {$mode delphi}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, AndroidWidget, Laz_And_Controls, Laz_And_GLESv2_Canvas,
  10.   Laz_And_GLESv2_Canvas_h;
  11.  
  12. type
  13.  
  14.   { TAndroidModule1 }
  15.  
  16.   TAndroidModule1 = class(jForm)
  17.     jButton1: jButton;
  18.     jCanvasES2_1: jCanvasES2;
  19.     jTimer1: jTimer;
  20.     procedure AndroidModule1Close(Sender: TObject);
  21.     procedure jButton1Click(Sender: TObject);
  22.     procedure jCanvasES2_1GLDraw(Sender: TObject);
  23.     procedure jTimer1Timer(Sender: TObject);
  24.   private
  25.     var
  26.       grScaleX, grScaleY: Single; // Used internally for graphics engine
  27.     procedure grCalculateScaleValues;
  28.   end;
  29.  
  30. var
  31.   AndroidModule1: TAndroidModule1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TAndroidModule1 }
  38.  
  39. procedure TAndroidModule1.AndroidModule1Close(Sender: TObject);
  40. begin
  41.   jTimer1.Enabled := False;
  42. end;
  43.  
  44. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  45. begin
  46.   jTimer1.Enabled := not(jTimer1.Enabled);
  47. end;
  48.  
  49. procedure TAndroidModule1.jCanvasES2_1GLDraw(Sender: TObject);
  50. var
  51.   i: Integer;
  52. begin
  53.   jCanvasES2_1.Screen_Setup (jCanvasES2_1.Width, jCanvasES2_1.Height, xp2D,cCull_YES);
  54.   jCanvasES2_1.Screen_Clear(1,1,1,1);
  55.   grCalculateScaleValues;
  56. end;
  57.  
  58. procedure TAndroidModule1.jTimer1Timer(Sender: TObject);
  59. begin
  60.   jCanvasES2_1.Refresh;
  61. end;
  62.  
  63. procedure TAndroidModule1.grCalculateScaleValues;
  64. begin
  65.   if (jCanvasES2_1.Height = 0) then Exit;
  66.   grScaleX := jCanvasES2_1.Width/jCanvasES2_1.Height;
  67.   grScaleX := 1;
  68. end;
  69.  
  70. end.

- If I remove grCalculateScaleValues (line #65, #66, #67), the crash won't happen.
- Or if I remove Screen_Clear (
line #54), the crash won't happen too.

How to reproduce:
01. Download the code, compile and build the apk.
02. Copy the apk to your mobile phone and run it.
03. Click the "Start" button once.
04. Press the white rectangle repeatedly as fast as possible. I use both my thumbs.
05. It crashes with message "Unfortunately, MicroWorld has stopped".

The code compiled using Lazarus 1.8.0 64-bit LAMW 0.7.0.0 (svn 695). Tested on Redmi 4X Octa-core 1.40GHz Android 6.0.1.

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #1 on: January 18, 2018, 06:34:41 pm »
This is the apk for testing.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: A LAMW Bug?
« Reply #2 on: January 27, 2018, 05:39:11 pm »

Hello, Handoko!

Ok. I will try fix it!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: A LAMW Bug?
« Reply #3 on: February 01, 2018, 04:04:14 am »
Added methods:
   DispatchTouchDown(_value: boolean )
   DispatchTouchMove(_value: boolean )
   DispatchTouchUp(_value: boolean)

use:
Code: Pascal  [Select]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. begin
  3.   jCanvasES2_1.DispatchTouchDown(False);
  4.   jCanvasES2_1.DispatchTouchMove(False);
  5.   jCanvasES2_1.DispatchTouchUp(False);
  6. end;
  7.  



Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #4 on: February 09, 2018, 03:32:08 pm »
Failed to correctly install svn 696.

I manually downloaded svn 696 and installed as how I usually did (open and install: tfpandroidbridge_pack, lazandroidwizardpack, amw_ide_tools). All these 3 packages were able to be compiled and installed, rebuilding the IDE was okay too. But if I open my android project and build, I get error. See the image below.

If I install LAMW using Online Package Manager, everything seemed to be okay except the DispatchTouchDown/Move/Up commands aren't recognized. So I think the Online Package Manager still using svn 695 or below.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1479
Re: A LAMW Bug?
« Reply #5 on: February 10, 2018, 01:32:23 am »

Quote
But if I open my android project and build, I get error

What about only open??  bug?
or the bug is on build?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #6 on: February 10, 2018, 03:33:57 am »

Quote
But if I open my android project and build, I get error

What about only open??  bug?
or the bug is on build?

- Manually install svn 696, rebuild Lazarus IDE ---> no error
- Manually install svn 696, open my android project ---> no error
- Manually install svn 696, open non android project ---> no error
- Manually install svn 696, open my android project and build ---> get error
- Manually install svn 696, open non android project and build ---> no error
- Install LAMW using OPM, open my android project and build ---> no error
- Install LAMW using OPM, build DispatchTouchDown/Move/Up ---> fail

I tested several times, those above are the results. So I believe I managed to install LAMW svn 696 but it wasn't installed correctly. Maybe there is something wrong with my Lazarus, I haven't tested with clean installation.

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #7 on: March 17, 2018, 06:02:48 am »
I retested LAMW again, now with revision 697. But still no luck:

- Manually uninstalled all the previous LAMW from my computer
- Downloaded LAMW  revision 697 using RapidSVN
- Installed the packages: tfpandroidbridge_pack, lazandroidwizardpack, amw_ide_tools
- All the 3 packages were installed successfully without error
- I can open my LAMW projects without problem
- But compiling (Ctrl+F9) old projects, I got "List Index (4427627) out of bounds" error
- Same error if using build (Shift+F9)
- Same error when compiling AppDemo1 (demo supplied by LAMW)
- No problem when compiling non-Android projects
- Tested on Lazarus 1.8.0 64-bit Gtk2 FPC 3.0.4 Ubuntu Mate 17.10

But if compiling a new LAMW project (File > New > Android [GUI] JNI Module [Lamw]), it works.

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: A LAMW Bug?
« Reply #8 on: March 17, 2018, 02:45:23 pm »
Cannot reproduce on Lazarus 1.8.2 64-bit Gtk2 FPC 3.0.4 Ubuntu 16.04.
It should be noticed, that for successful compilation of AppDemo1 it is needed to clear Custom options.
What android SDK do you use?
When you've got an exception is there any console output? (some kind of stacktrace would be appreciated)

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #9 on: March 17, 2018, 06:43:11 pm »
There were no any output on the Message Window. The IDE will exit immediately if I click 'Abort'. If I click 'Ok', the error warning will be close, still the same no any output on the Message Window.

The error shows up immediately after clicking the 'compile' button. This makes me think this is an issue on the IDE, not FPC because the 'real' compiling process hasn't started yet.

It should be noticed, that for successful compilation of AppDemo1 it is needed to clear Custom options.

I didn't update LAMW frequently. But previously compiling the AppDemo1 just worked without clearing custom options nor modify any settings.

Cannot reproduce on Lazarus 1.8.2 64-bit Gtk2 FPC 3.0.4 Ubuntu 16.04.

Thanks for the testing. I will perform more tests and report back with more info later. I'm thinking to try it on Lazarus 1.8.2.

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: A LAMW Bug?
« Reply #10 on: March 17, 2018, 07:48:22 pm »
Try to start Lazarus IDE manually by "startlazarus" in console and look on the messages in this console when the error you mentioned arise.

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #11 on: March 17, 2018, 07:54:30 pm »
I did as what you said:

Quote
TApplication.HandleException List index (4427627) out of bounds
    Stack trace:
    $0000000000515DA2

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: A LAMW Bug?
« Reply #12 on: March 17, 2018, 09:42:56 pm »
Try to rebuild Lazarus IDE with debug info (use "Debug IDE" profile in "Configure build Lazarus" dialog). Stacktrace should contain source file names and line numbers.

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: A LAMW Bug?
« Reply #13 on: March 18, 2018, 07:35:57 am »
Here are the messages when compiling the AppDemo1:

A.S.

  • Jr. Member
  • **
  • Posts: 76
Re: A LAMW Bug?
« Reply #14 on: March 18, 2018, 10:13:36 am »
Not sure, but probably your LAMW was compiled with different debug info. Open LazAndroidWizardPack package (menu Package->Open loaded package... and search for "LazAndroidWizardPack" then open it) and check that Custom options contain only "$(IDEBuildOptions)" (w/o quotes).
You can also try to rebuild IDE (with debug info) with "clean all" options (for the case if LAMW was not recompiled).
As far as I can see, lazideintf.pas:648 should call TLamwSmartDesigner.OnProjectSavingAll, so error may be somewhere in this function.