Recent

Author Topic: [solved] LAMW - app crash when starting  (Read 6319 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
[solved] LAMW - app crash when starting
« on: November 07, 2017, 03:55:49 pm »
After my intensive tests, I believe jCanvasES2.Texture_Load_All can cause crash when starting the program.

01. File > New > Android [GUI] JNI Module [Lamw]
02. Put a jImageList on the form
03. Put a jCanvasES2 on the form
04. Set the property jCanvasES2_1.Images := jImageList1
05. Double the the jImageList1 (on the form)
06. Click "Add" to select and use the image
07. Put this code for jCanvasES2.OnGLCreate:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jCanvasES2_1GLCreate(Sender: TObject);
  2. begin
  3.   jCanvasES2_1.Texture_Load_All; //  <--- This line cause runtime error
  4.   jCanvasES2_1.Shader_Compile('simon_Vert', 'simon_Frag');
  5.   jCanvasES2_1.Shader_Link;
  6. end;

Compile the code, build the apk and run it. So far it won't crash. But the more code I add the more frequent it will crash on starting. For example, you can add some jButtons, a jTimer, etc.

Or you can use glTest1 I submitted some days ago:
http://forum.lazarus.freepascal.org/index.php/topic,38777.msg264878.html#msg264878
Remember, you need to add a jImageList, use/add an image and the code for jCanvasES2_1GLCreate to my glTest1 for testing. The error almost always reproducible.

Run the application and quit (using Back Button), do it repeatedly and you will get crash. The message is "Unfortunately, LamwGUIProject1 has stopped".

And one thing I'm sure is if I remove the line "jCanvasES2_1.Texture_Load_All;", it will never crash.
« Last Edit: November 16, 2017, 07:27:53 am by Handoko »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #1 on: November 07, 2017, 10:47:06 pm »
Quote
Run the application and quit (using Back Button), do it repeatedly and you will get crash.

my guess: the "jCanvasES2_1GLCreate"  is call every time you reactive the app and jCanvasES2.Texture_Load_All cause memory overflow...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: LAMW - app crash when starting
« Reply #2 on: November 08, 2017, 01:35:23 am »
It is not only happened on my codes. AppDemo1 also has this problem, it is on:
AppDemo1 > OpenGL2 2D (jButton9Click) > unit11.pas

Any solution or workaround for it? I put
jCanvasES2_1.Texture_UnLoad_All;
on AndroidModuleClose, but does not help.

On my tests, I found the larger the image the more frequent the error happens. For example try 1024 x 1024 images. I googled the Internet, they said most phones that support OpenGL ES2 should support 1024 x 1024 textures.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #3 on: November 08, 2017, 04:29:35 am »
There is a bug here. Please try a fix:

Code: Pascal  [Select][+][-]
  1. Procedure jCanvasES2.Texture_Clear;
  2. var
  3.   i : Integer;
  4. begin
  5.   if not FInitialized then Exit;
  6.   for i := 0 to  TexturesCount -1   do  //not cTextureMax  !!!!!
  7.   begin
  8.     if Textures[i].Active then
  9.     begin
  10.       glDeleteTextures(1,@Textures[i].ID);
  11.       Textures[i].Active := False;
  12.     end;
  13.   end;
  14.   TexturesCount:= 0;
  15. end;
  16.  

But, AppDemo1 continue to fail .... I will try some solution!
« Last Edit: November 08, 2017, 04:57:54 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #4 on: November 10, 2017, 07:11:31 am »

Hello,  Handoko!

We have good News!!!

I fixed OpenGL stuff in AppDemo1 !

cause: in mult-form app, when user click the "backbutton"  the java OpenGLSurfaceView is
destroyed.... so we need "ReInit"  [not "Show']  to recreate the surface!

Please, update your LAMW stuff...

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

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: LAMW - app crash when starting
« Reply #5 on: November 10, 2017, 07:40:49 am »
Thank you.

But how should I apply the fix in my codes? Do I do svn update and recompile the code? Or do I use Texture_Clear instead of Texture_UnLoad_All?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #6 on: November 10, 2017, 08:04:53 pm »
Quote
Do I do svn update e and recompile the code...

Yes!

Recompile/reinstall all package, then open "AppDemo1"  and:

menu "Run" ---> "Clean up and Build ..."

menu "Run" ---> "[Lamw] Build Android Apk and Run"

NOTE: This update solve "AppDemo1" bug ....  If it will solve your app bug need some tests...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: LAMW - app crash when starting
« Reply #7 on: November 11, 2017, 04:42:21 am »
Thank you for the fix.

I updated to version 684. On my simple test, it never crashed. I will write a demo game for testing to see if it working correctly. I will report back some days later.

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: LAMW - app crash when starting
« Reply #8 on: November 13, 2017, 04:38:28 am »
The issue hasn't fully solved. I tested on LAMW rev 686, I still can reproduce the problem using the same way as I explained on my previous post. I use an image I drew myself, it saved using GIMP. It is a 256 x 256 24-bit png + alpha image, most OpenGL-supported hardwares should have no problem with it.

You can use the image I used for testing, or you can use others too if you want. Duplicate the image and name it differently (ex: img1.png ... img6.png) and add them to the jImageList. The more images added to jImageList, the higher chances it will crash when starting the app.

1 image  ->   ±0% chance to crash
3 images ->  ±25% chances to crash
6 images -> ±100% chances to crash


If I resize the them to 128 x 128 and test again, the chances to crash will drop a lot.
« Last Edit: November 13, 2017, 07:09:42 am by Handoko »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #9 on: November 13, 2017, 05:00:56 am »
Ok , let's separate the problems:

1) In "AppDemo1",   jCanvasES component crash the App in run time after backbutton  and a new attempt to reload it.

::fixed using jForm "ReInit"  [not "Show"]

2)  The Lazarus IDE crash when LAMW wizard try open/load a multi-forms project...

::fixed by last Anton/Odisey1245 (a.k.a  A.S) commit.

and

3) OpenGL/jCanvasES  based App  crash in run time if we have a heavy use of images.... [not solved, yet.....]
« Last Edit: November 13, 2017, 05:05:55 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: LAMW - app crash when starting
« Reply #10 on: November 16, 2017, 05:23:54 am »
Quote
3) OpenGL/jCanvasES  based App  crash in run time if we have a heavy use of images.... [not solved, yet.....]

Ok. I got some improvement here!

Please, update LAMW stuff and do some test......

My Code:

Code: [Select]
procedure TAndroidModule1.jCanvasES2_1GLCreate(Sender: TObject);
begin
 jCanvasES2_1.Texture_Load_All;   //load six test.png  256x256
 jCanvasES2_1.Shader_Compile('simon_Vert', 'simon_Frag');
 jCanvasES2_1.Shader_Link;
end;

procedure TAndroidModule1.jCanvasES2_1GLDestroy(Sender: TObject);
begin
  jCanvasES2_1.Texture_UnLoad_All;     
end;

Thank you!
« Last Edit: November 16, 2017, 05:30:22 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: LAMW - app crash when starting
« Reply #11 on: November 16, 2017, 07:27:33 am »
Downloaded and tested version 687. I can't reproduce the crash anymore. I marked this issue solved. Thank your for the fix.

I saw you use jCanvasES2_1.Texture_UnLoad_All; on jCanvasES2_1GLDestroy. Do we really need it? I do not use Texture_Unload_All, and my code seems to work correctly.

There is one thing I can't understand, my old code rebuilt and compiled using version 687 can't start. Previously it had 70% of crash but now it always crash. The strange is, I started a new project and made it similar to the old one by copy-paste code from the old one and set all the events and settings the same. It works 100% without crash. Why?

My guess, maybe there is something related with the autocreated java codes? Is there anything we can do to force renew the java things?

I ever accidentally deleted the java codes. The project became unusable although the pascal codes are kept. Please consider the feature to regenerate the java codes and some other things (scripts, etc).

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: [solved] LAMW - app crash when starting
« Reply #12 on: November 16, 2017, 04:42:01 pm »
Quote
Do we really need it? I do not use Texture_Unload_All, and my code seems to work correctly.

I noticed that the images are always reload from file when the app is re-init,  so I thought it would be better unload them ... in an attempt to avoid overflow...

Quote
There is one thing I can't understand, my old code rebuilt and compiled using version 687 can't start.

You can try:

1)  In Dialog Open Package:  "More"--->  Recompile Clean

2)  Open the Project and go to menu "Run" ---> "Clean up and Build"

Quote
Is there anything we can do to force renew the java things?

java things are always automatically update and recreate!!!!


Thank you!

PS. New "demos"  are welcome!!!!

EDITED:  More code ...

Code: [Select]
procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
const
    ....
var
  i: Integer;
begin
  // Setup screen
   .....
   .....
  // Start timer
  FGameOn:= False;  // set some global here...
  jTimer1.Enabled := True;
end;

Code: [Select]
procedure TAndroidModule1.jCanvasES2_1GLCreate(Sender: TObject);
begin
 jCanvasES2_1.Texture_Load_All;
 jCanvasES2_1.Shader_Compile('simon_Vert', 'simon_Frag');
 jCanvasES2_1.Shader_Link;
 FGameOn:= True;
end;

Code: [Select]
procedure TAndroidModule1.jTimer1Timer(Sender: TObject);
begin
   if  FGameOn then
     jCanvasES2_1.Refresh;
end;
« Last Edit: November 16, 2017, 05:04:31 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Handoko

  • Hero Member
  • *****
  • Posts: 5159
  • My goal: build my own game engine using Lazarus
Re: [solved] LAMW - app crash when starting
« Reply #13 on: November 16, 2017, 05:14:24 pm »
Quote
There is one thing I can't understand, my old code rebuilt and compiled using version 687 can't start.

You can try:

1)  In Dialog Open Package:  "More"--->  Recompile Clean

2)  Open the Project and go to menu "Run" ---> "Clean up and Build"

Quote
Is there anything we can do to force renew the java things?

java things are always automatically update and recreate!!!!

Nope. You misunderstood what I mean, maybe I didn't explain well. If the problems are so simple, I should already figure it out. It's okay, I have my workarounds for them. It is not important now, I will start new thread later. Now I'm writing an OpenGL ES2 game using LAMW. When doing the game, I found some new issues. Still not sure how to reproduce the problems. But that's okay, they are not critical, just some minor bugs. After I finish it, I will release the source codes and report all the bugs I found.

Thank you for your hard works. It makes my dream to build Android games comes true. You won't believe how many tools and efforts I've done to do it.
« Last Edit: November 16, 2017, 05:16:30 pm by Handoko »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: [solved] LAMW - app crash when starting
« Reply #14 on: November 16, 2017, 05:38:58 pm »

Quote
When doing the game, I found some new issues.

Here, too. I got:
Quote
E/libEGL(10180): call to OpenGL ES API with no current context (logged once per thread)

And I still do not know how to solve ...   :-X :-X
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018