"EachIn" bug or my fault?

BlitzMax Forums/BlitzMax Programming/"EachIn" bug or my fault?

_JIM(Posted 2010) [#1]
Hi,

Since BlitzMax offer such godies as using "EachIn" when looping through lists, I obviously decided to use it. But is this a good option or not?

Recently I've had a rather strange crash. I've narrowed it down to this: If I use "ShowGadget" and "HideGadget" on a property grid under certain conditions, I get 3 different crashes precisely on a for that looks like this:

For Local tmpP:TProp = EachIn Self.PropList
	tmpP.Owner = Self
	tmpP.Draw(VD)
Next


If I don't show/hide the gadget, everything runs just fine. However, setting up the for like this:

For Local i:Int = 0 Until Self.PropList.Count()
	Local tmpP:TProp = TProp(Self.PropList.ValueAtIndex(i))
	tmpP.Owner = Self
	tmpP.Draw(VD)
Next


Solves the problem. This is rather strange as I've never had such weird behavour from BMax.

Any thoughts on this?


Dreamora(Posted 2010) [#2]
we need more code than this as this shows nothing about your setup at all I fear.


_JIM(Posted 2010) [#3]
Sadly, this is the problem. I can't reproduce it on a smaller scale. If this get out of control, I'll try to isolate it in a small example.

I was thinking that maybe someone else had some experience with voodoo like this.


Zakk(Posted 2010) [#4]
Are you running it in debug?


_JIM(Posted 2010) [#5]
Yes, that's how I identified the line. What's more weird is that out of all the crashes, most are "EXCEPTION_ACCESS_VIOLATION", some are just freezes and windows asks me to debug and a few are "EXCEPTION_PRIV_INSTRUCTION".


Czar Flavius(Posted 2010) [#6]
You'd be better off converting it to an array first rather than using PropList.ValueAtIndex(i) in a loop, as it's very slow.

This is written off the top of my head so I might have remembered the names wrong, but try something like
Local link:TLink = Problist.First()
While link
	Local prop:TProp = TProp(link)
	prop.Owner = Self
	prop.Draw(VD)
	link = link.NextLink()
Wend



ShadowTurtle(Posted 2010) [#7]
Sorry, Czar Flavius. I think this should not a solution. The bug should be fixed.


1. i think there is a hard blitzmax bug/problem going on.. Oo

2. System: Windows 7, 64bit, AMD 2-core. I do use _not_ the maxide community edition. I do use the original maxide. BlitzMax V1.37.

3. i deleted BlitzMax V1.36 complete before i huv installed V1.37. I deleted all damn files.

4. errors like "EXCEPTION_ACCESS_VIOLATION", "EXCEPTION_PRIV_INSTRUCTION" are _not_ random!

5. add the following error into the list:
"Unhandled Exception:setMemBit error: membit already set"
screenshot:


6. in release-mode my program make _no_ problems. No memory leaks. No memory bugs. No etc.

7. in debug-mode: See following screens: (IMPORTANT: Point 7. is available)







8. Error structure (debug output, MaxIDE). See screenshot:


9. Complete informations (goes to the technical guy @ brl ^^):
'Function ObjectEnumerator' in "/mod/brl.mod/linkedlist.mod/linkedlist.bmx"
Type "Type TList", Line: 89
Marked code: "Local enum:TListEnum=New TListEnum"
Line: 404

'Method FlushBrushes(pRecurse:Int = True)' in "/mod/maxgui.mod/win32/win32maxguiex.mod/win32maxguiex.bmx"
Type "Type TWindowsPanel Extends TWindowsGadget", Line: 4101
Marked code: "For Local tmpGadget:TWindowsGadget = EachIn kids"
Line: 4312

'Method FlushBrushes(pRecurse:Int = True)' in "/mod/maxgui.mod/win32/win32maxguiex.mod/win32maxguiex.bmx"
Type "Type TWindowsWindow Extends TWindowsGadget", Line: 1343
Marked code: "tmpGadget.FlushBrushes()"
Line: 1787

'Method WndProc(hwnd,msg,wp,lp)' in "/mod/maxgui.mod/win32/win32maxguiex.mod/win32maxguiex.bmx"
Type "Type TWindowsGadget Extends TGadget", Line: 831
Marked code: "FlushBrushes()" (on event "WM_WINDOWPOSCHANGING"!?)
Line: 1077
^ WTF!?!?!? The event WM_WINDOWPOSCHANGING was never started! No window resize etc..! I clicked on a treeview entry.
^ I think this error has with the event system (memory leak in debug mode?) to do.

'Method WndProc(hwnd,msg,wp,lp)' in "/mod/maxgui.mod/win32/win32maxguiex.mod/win32maxguiex.bmx"
Type "Type TWindowsWindow Extends TWindowsGadget", Line: 1343
Marked code: "Return Super.WndProc(hwnd,msg,wp,lp)"
Line: 1732
^ can the error to do with "Super"!? (see top)

'Function ClassWndProc(hwnd,msg,wp,lp) "win32"' in "/mod/maxgui.mod/win32/win32maxguiex.mod/win32maxguiex.bmx"
Type "Type TWindowsGUIDriver Extends TMaxGUIDriver", Line: 279
Marked code: "If owner Return owner.WndProc(hwnd,msg,wp,lp)"
Line: 495

'Function HandyRPG' (there is no main-function or main-type around the app) in "handyrpg.bmx"
Type: None.
Marked code: "playeritem_actualgui()"
By the way...
playeritem_actualgui does ..
... no window resize. (see comment at top)
... no send events
... no getting events
... no resize gadgets
so.. what is going on with pointing on the following code section (debug-mode)!?
Select msg
	Case WM_WINDOWPOSCHANGING ' <= "WM_WINDOWPOSCHANGING" must be started.
		FlushBrushes() ' <= this is the next way, on going producing the error/bug.
EndSelect


10. The bug must also positioned into the blitzmax's own debugger source wich handles events. Is a pointer setted wrong?


SebHoll(Posted 2010) [#8]
I can have a look into this for you, but you will need to send me the source (e-mail address in the profile).


_JIM(Posted 2010) [#9]
Seb, I can send you the source and anything else required as soon as I get home. (about 8 hours from now)

It does seem like there's something wrong with enumerators showing up as null suddenly. The crash I described also implied an enumerator and avoiding it solved the problem.

EDIT: This is odd. For some reason I can't seem to be able to reproduce it. I've rolled back the source code but it doesn't happen anymore. I'll keep an eye out and post if it pops again.