[Solved] How I can stop a event that is queued?
BlitzMax Forums/Brucey's Modules/[Solved] How I can stop a event that is queued?
| ||
How I can stop a event that is queued? the event: ' --------------------------------------------------------------------------------[OnInit]--- Method OnInit:Int() timer = New wxTimer.Create(Self) ConnectAny(wxEVT_PAINT, OnPaint) ' I can set timer to 0 and only call OnPaint when I .refresh() the wxWindow window ConnectAny(wxEVT_TIMER, OnTick) ' If I Rem this line I don't get the EXCEPTION_ACCESS_VIOLATION Error! End Method ' ------------------------------------------------------------------------[CreateNewMax2D]--- Method CreateNewBLL2D:TBLL2D(_parent:wxWindow, _id:Int, _timer:Int, _x:Int, _y:Int, _width:Int, _height:Int) id = _id CreateWin(_parent, _id, _x, _y, _width, _height) SetBackgroundStyle(wxBG_STYLE_CUSTOM) If _timer <> 0 Then timer.Start(_timer) Return Self End Method ' --------------------------------------------------------------------------------[OnTick]--- Function OnTick(event:wxEvent) wxWindow(event.parent).Refresh() End FunctionIf I stop my Lua script from withing the script I sometime get: EXCEPTION_ACCESS_VIOLATION It's the timer that call BlitzMax OnPaint even if the script been stopped! the Lua script is closed and the event is calling BlizMax OnPaint that try call the Lua OnPaint that give me the EXCEPTION_ACCESS_VIOLATION Can I somehow look in the Type event queue. and remove the event? |
| ||
The EAV means you access something which is null. Instead of removing the event, you should handle it - and set it to "handled", so that others ignore it. Alternatively: only handle things in "onPaint" if a variable is true. When you stop your script, "false" the variable and it should do. bye Ron |
| ||
Method DoOnPaint() If Not BLLua.L Then Return ' L is alive here SetGraphics wxGraphics(Self) MOBii_InEvent :+ 1 BLLua.MOBii_CallTableFunctionInt("SYS", "OnPaint", id) ' L die in here! MOBii_InEvent :- 1 If BLLua.halt Then BLLua.StopLua() End MethodI am in BLLua.MOBii_CallTableFunctionInt("SYS", "OnPaint", id) when I terminate the script then the timer call: ' ------------------------------------------------------[BLLua.MOBii_CallTableFunctionInt]--- Method MOBii_CallTableFunctionInt:Int(_Table:String, _Function:String, _Data:Int) If L Then ' He pass this L Local _ret:Int = -1 lua_pushstring(L, _Table) ' get the table lua_gettable(L, LUA_GLOBALSINDEX) lua_pushstring(L, _Function) ' get the function from the table lua_gettable(L, -2) ' note: -2 is the table, -1 is the key If lua_type(L, -1) = LUA_TFUNCTION Then lua_pushinteger(L, _Data) ' 1st argument Local Lua_Err:Int = lua_pcall(L, 1, 0, 0) ' call _Function with 1 arguments and 0 result Print_Lua_Error(Lua_Err, 1) lua_pop(L, 1) ' pop the _Table table from the stack since it's no longer needed Return Lua_Err End If End MethodInside this call: lua_pcall(L, 1, 0, 0) the terminate script Set L = Null and I get the EXCEPTION_ACCESS_VIOLATION 1. timer is in queue 2. I close Lua and put the terminate script in queue 3. timer is call OnPaint that call lua_pcall(L, 1, 0, 0) and while inside the terminate script in queue get called and set L to Null This is the only way I can explain how he got inside lua_pcall(L, 1, 0, 0) When I run the terminate code it stop the timer |
| ||
If you do not use threading, then execution of your app logic is halted, events wont get processed until you finished whatever you are doing in lua. Maybe you are getting a segfault within your Lua script processing ("MOBii_CallTableFunctionInt") Do not rely on "print" or so. Just run it via a Debugbuild and see where it fails. bye Ron |
| ||
Thank thee Derron, I been wrapping my head in this for the last 3 days I learn HOWTO [F8] really fast I learn that ALL the ConnectAny(...) is going thru the EventFactory, I need to fix that I add this in top of terminate Lua script: Method StopLua() If MOBii_InEvent Then DebugLog "Start Timer" Return End If ... End MethodIf MOBii_InEvent > 0 it mean he is in a Lua function I create first a timer that call StopLua() after 50ms But I didn't need to do that because If I halt the script he have only 1 thing in mind to execute: StopLua() until he succeed If I didn't fix this I could forget any wxmax2D OnPaint functionality Now I can continue see if I can get any max2D surface to work thanks again |