[solved] LAMW - app crash when starting lazarus / 43-Android ---------------------------------------------------------------------- Handoko · 2017-11-07 14:55 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.jCanvasES2_1GLCreate(Sender: TObject);begin  jCanvasES2_1.Texture_Load_All; //  <--- This line cause runtime error  jCanvasES2_1.Shader_Compile('simon_Vert', 'simon_Frag');  jCanvasES2_1.Shader_Link;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.ht ml#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. ---------------------------------------------------------------------- jmpessoa · 2017-11-07 21:47 QuoteRun 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... ---------------------------------------------------------------------- Handoko · 2017-11-08 00:35 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 · 2017-11-08 03:29 There is a bug here. Please try a fix: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure jCanvasES2.Texture_Clear;var  i : Integer;begin  if not FInitialized then Exit;  for i := 0 to  TexturesCount -1   do  //not cTextureMax  !!!!!  begin    if Textures[i].Active then    begin      glDeleteTextures(1,@Textures[i].ID);      Textures[i].Active := False;    end;  end;  TexturesCount:= 0;end;  But, AppDemo1 continue to fail .... I will try some solution! ---------------------------------------------------------------------- jmpessoa · 2017-11-10 06:11 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! ---------------------------------------------------------------------- Handoko · 2017-11-10 06:40 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 · 2017-11-10 19:04 QuoteDo 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... ---------------------------------------------------------------------- Handoko · 2017-11-11 03:42 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 · 2017-11-13 03:38 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. ---------------------------------------------------------------------- jmpessoa · 2017-11-13 04:00 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.....] ---------------------------------------------------------------------- jmpessoa · 2017-11-16 04:23 Quote3) 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! ---------------------------------------------------------------------- Handoko · 2017-11-16 06:27 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 · 2017-11-16 15:42 QuoteDo 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... QuoteThere 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" QuoteIs 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; ---------------------------------------------------------------------- Handoko · 2017-11-16 16:14 Quote from: jmpessoa on November 16, 2017, 04:42:01 pmQuoteThere 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" QuoteIs 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. ---------------------------------------------------------------------- jmpessoa · 2017-11-16 16:38 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 ... ---------------------------------------------------------------------- Handoko · 2017-11-16 16:52 Mine is different. I don't use any high-end OpenGL commands.