Range check error lazarus / 12-Debugger ---------------------------------------------------------------------- Vytautasrask · 2011-04-25 13:07 I try to compile and run program on 64 bit and get this error Linux: Code: [Select]$ ./KaM_Remake [WARNING] Out of OEM specific VK codes, changing to unassigned [WARNING] Out of unassigned VK codes, assigning $FF [FORMS.PP] ExceptionOccurred   Sender=ERangeError   Exception=Range check error   Stack trace:   $0000000000580AAD line 1381 of KM_ResourceGFX.pas   $00000000005716A1 line 138 of KM_ResourceGFX.pas   $000000000057129E line 97 of KM_ResourceGFX.pas   $0000000000535F72 line 139 of KM_Game.pas   $00000000004D9C00 line 479 of KM_Unit1.pas   $00000000004D7EDA line 186 of KM_Unit1.pas   $00000000004A1975 line 77 of KaM_Remake.dpr TApplication.HandleException Range check error   Stack trace:   $0000000000580AAD line 1381 of KM_ResourceGFX.pas   $00000000005716A1 line 138 of KM_ResourceGFX.pas   $000000000057129E line 97 of KM_ResourceGFX.pas   $0000000000535F72 line 139 of KM_Game.pas   $00000000004D9C00 line 479 of KM_Unit1.pas   $00000000004D7EDA line 186 of KM_Unit1.pas   $00000000004A1975 line 77 of KaM_Remake.dpr And simple range check error box on win64. On win32 it works. Full code here: http://code.google.com/p/castlesand/source/checkout How can I fix this? ---------------------------------------------------------------------- marcov · 2011-04-25 13:38 I'd start by breaking up that expression into multiple lines to see what exactly causes it. I really quickly (using the svn browse feature) tried to look what is wrong, and I don't see instantly what is happening. If the tip above yields no result, then start to simplify the example. ---------------------------------------------------------------------- JuhaManninen · 2011-04-25 19:50 I get errors like: Unable to locate file: "/home/juha/SW/castlesand-read-only/trunk/Data\misc\text.lib" and Unable to locate file: "/home/juha/SW/castlesand-read-only/trunk/Data\misc\remake.eng.libx" when strating the prog. There is no "text.lib" but there is "text.fr.lib" and "text.svk.lib". There is "remake.eng.libx" but I think the wrong path separators are the problem. Juha ---------------------------------------------------------------------- Vytautasrask · 2011-04-27 07:05 You can find those files in: http://code.google.com/p/castlesand/downloads/list (demo 5) Or just ignore those errors for now. When I will have more time I will try to simplify example too ---------------------------------------------------------------------- JuhaManninen · 2011-04-27 07:49 You have lots of code as below. No wonder it does not work on Linux. I didn't test on Windows but maybe there are 64-bit issues, too. To port the code to cross-platform, get rid of HWND. It should work but at least searching the problems is easier without it. Use the component references directly (TPanel, TWinControl...). For OpenGL, see http://wiki.lazarus.freepascal.org/OpenGL. It says about context handling: QuoteLazarus includes a TOpenGLControl - a LCL control with an OpenGL context. The lazarus package LazOpenGLContext can be found lazarus/components/opengl/lazopenglcontext.lpk. An example can be found in lazarus/examples/openglcontrol/openglcontrol_demo.lpi. Code: [Select]constructor TRender.Create(RenderFrame:HWND; aVSync:boolean); begin   Inherited Create;   {$IFDEF MSWindows}   SetRenderFrame(RenderFrame, h_DC, h_RC);   SetRenderDefaults;   glDisable(GL_LIGHTING); //We don't need it   fOpenGL_Vendor   := glGetString(GL_VENDOR);   fLog.AddToLog('OpenGL Vendor:  '  +fOpenGL_Vendor);   fOpenGL_Renderer := glGetString(GL_RENDERER); fLog.AddToLog('OpenGL Renderer:  '+fOpenGL_Renderer);   fOpenGL_Version  := glGetString(GL_VERSION);  fLog.AddToLog('OpenGL Version:  ' +fOpenGL_Version);   SetupVSync(aVSync);   BuildFont(h_DC, 16, FW_BOLD);   setlength(RenderList,512);   {$ENDIF}   {$IFDEF Unix}     MessageBox(Form1.Handle,'Trender.Create not working', 'Error', MB_OK);   {$ENDIF} end; destructor TRender.Destroy; begin   setlength(RenderList,0);   {$IFDEF MSWindows}   wglMakeCurrent(h_DC, 0);   wglDeleteContext(h_RC);   {$ENDIF}   {$IFDEF Unix}   //do not know how to fix them :(   //just error for now   MessageBox(Form1.Handle,'glXMakeCurrent and glXDestroyContext not working', 'Error', MB_OK);   //glXMakeCurrent(display, wid, util_glctx);   //glXDestroyContext(h_RC);   {$ENDIF}   Inherited; end; ---------------------------------------------------------------------- Vytautasrask · 2011-04-27 16:20 Thx for help. I think I have to fix that crash first then opengl or they are related? ---------------------------------------------------------------------- JuhaManninen · 2011-04-27 21:20 Quote from: Vytautasrask on April 27, 2011, 06:20:47 pmI think I have to fix that crash first then opengl or they are related? I don't know. Just fix the problems one by one and finally it works perfectly. Juha ---------------------------------------------------------------------- Vytautasrask · 2011-05-11 17:40 I do not know how to replace HWND. I even not sure what HWND is. Can you help with that constructor? ---------------------------------------------------------------------- JuhaManninen · 2011-05-12 10:59 Quote from: Vytautasrask on May 11, 2011, 07:40:05 pmI do not know how to replace HWND. I even not sure what HWND is. Can you help with that constructor? HWND is a Windows specific "Window Handle". Many LCL cross-platform functions support it, too, but it is not needed if you make a proper cross-platform program. In this castlesand code HWND is used for OpenGL calls. They will go away "automatically" when you use the LazOpenGLContext I wrote about. Many "wgl..." functions that don't exist on Linux are implemented in the context class. Then, there are libs in "Common" directory. At least zlib and png are supported by FPC/Lazarus and FastMM is not needed. "Overbyte ICS" is some socket lib, maybe someone knows how to replace it. The code also has lots of useless IFDEFS. FPC/Lazarus is cross- platform and can handle most code without IFDEFS. If you want to support Delphi, too, then you need some IFDEFS. So, the porting is not trivial but it is realistic. It would be cool to get it working. Are you copying your changes to http://code.google.com/p/castlesand or to somewhere else, for others to look at them? Juha ---------------------------------------------------------------------- Vytautasrask · 2011-05-12 12:37 zlib is fixed and png is partialy ported already, yes I want to keep Delphi too. In branches/unix are the latest changes. We decided to disable net on Linux for a while. QuoteMany "wgl..." functions that don't exist on Linux are implemented in the context class. Where? ---------------------------------------------------------------------- JuhaManninen · 2011-05-12 21:37 Quote from: Vytautasrask on May 12, 2011, 02:37:11 pmQuoteMany "wgl..." functions that don't exist on Linux are implemented in the context class. Where? I meant the TOpenGLControl in package LazOpenGLContext. See my earlier post. Cross-platform opengl has functions for drawing but context initialization and handling is platform dependent. LazOpenGLContext tries to improve that. It works with LCL-Win, OS/X and GTK2, but not with QT yet. Juha ---------------------------------------------------------------------- Vytautasrask · 2011-05-13 09:09 Thx for help. ---------------------------------------------------------------------- JuhaManninen · 2011-05-13 11:10 One note: it may be easier to first port a Lazarus-only version and later implement Delphi support back by IFDEFs. Otherwise you will have lots of messy IFDEFed code during conversion. Juha