Jump to content

Program starts Freaking out after ~20 minutes


 Share

Recommended Posts

I have been working on the graph feature of my vistumbler program to try and get rid of the flickering of the graph. I came across this post which suggested using the windows API to do the drawing. I am using the functions created by "neogia".

I have my program graphing the way I want now, but after around 20 minutes the program starts messing up. all the controls move and are basically unusable. If i minimise the program it can't be maximized again (and the tab in the taskbar moves and messes up when i click on it). This happens on both my laptop and my desktop.

Any idea what may cause this? attached is the top of my window, usually controls would be there

I'm wonding if it has to do with my control resizing, but the problem did not start untill i implemented the new graph

The code that is having the problem is here --> http://techidiots.net/other/Vistumbler7pre6.zip

I am pretty sure my old prerelease version before the graph changes did not have this problem, that is located here --> http://forum.techidiots.net/forum/viewthre...d=10&pid=44

post-7295-1194292336_thumb.jpg

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Dude your code is 2384 lines long. Without isolating the problem area we can't be much help.

I'm not sure where the problem is. I am assuming its in the graphing feature. I was hoping someone had run into this before. I didn't expect you to look at my code and figure it out. I just provided it incase someone wanted to replicated the problem.

I can try to make something thats just the graph and fake data, but the problem may not even be with the graph for all i know. It works great for 20 minutes, then it gliches to death.

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Here is the graph part stripped out. Generating random information. I'll see if it has the same problem in 20 minutes

#include <GuiConstants.au3>
Dim $SigHist = '', $sizes, $sizes_old, $data, $data_old, $Graph_old, $Redraw =1, $LastSelected = -1
Global $gdi_dll, $user32_dll
Global $hWnd

Dim $Graphic_left
Dim $Graphic_width
Dim $Graphic_top
Dim $Graphic_height

;$Graph = 1
$Graph = 2

$Vistumbler = GUICreate("MyGUI", 908, 692, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetState()
$GraphicGUI = GUICreate("", 895.72, 386.19, 10, 60, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Vistumbler)
GUISetState()
$DataChild = GUICreate("", 895, 595, 0, 60, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Vistumbler)
GUISetState()
GUISwitch($Vistumbler)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        $SigHist = Random(0, 100) & '-' & $SigHist
        $data = $SigHist
        _SetControlSizes()
        _GraphApSignal()
    EndSelect
WEnd
Exit


Func _SetControlSizes()
    $a = WinGetPos($Vistumbler)
    WinMove($DataChild, "", 0, 60, $a[2] - 10, $a[3] - 115)
    $b = WinGetPos($DataChild);get child window size
    $sizes = $a[0] & '-' & $a[1] & '-' & $a[2] & '-' & $a[3] & '-' & $b[0] & '-' & $b[1] & '-' & $b[2] & '-' & $b[3]
    If $sizes <> $sizes_old Or $Graph <> $Graph_old Or $Redraw = 1 Then
        If $Graph <> 0 Then
            $Graphic_left = ($b[2] * 0.01)
            $Graphic_width = ($b[2] * 0.99) - $Graphic_left
            $Graphic_top = ($b[3] * 0.01)
            $Graphic_height = ($b[3] * 0.64) - $Graphic_top
            WinMove($GraphicGUI, "", $Graphic_left, $Graphic_top + 60, $Graphic_width, $Graphic_height)
        $sizes_old = $sizes
        $Graph_old = $Graph
    EndIf
EndFunc  ;==>_SetControlSizes

Func _GraphApSignal()
    If $Graph <> 0 Then; If the graph tab is selected, run graph script
            If $data <> $data_old Or $sizes <> $sizes_old Or $Redraw = 1 Then; if graph data changed, map new data
                DrawingStartUp($GraphicGUI)
                $max_graph_points = 100
                $base_right = $Graphic_width - 1
                $base_left = 0
                $base_top = 0
                $base_bottom = $Graphic_height - 1
                $base_x = $base_right - $base_left
                $base_y = $base_bottom - $base_top

                $max_graph_points = 125
                $data_old = $data
                $sizes_old = $sizes
                $splitdata = StringSplit($data, '-');Split signals into an array
                
                
                $GraphBack = CreateColor(215, 228, 242)
                $black = CreateColor(0, 0, 0)
                $red = CreateColor(255, 0, 0)
                $GraphGrid = CreateColor(0, 0, 255)
                
                If IsArray($splitdata) Then
                    If $Graph = 1 Then
                        If $splitdata[0] > $max_graph_points Then; If the array is grater that the max number of ports, set array size to the max size, else use the full size of the array
                            $arraylen = $max_graph_points
                        Else
                            $arraylen = $splitdata[0]
                        EndIf
                        $base_x_add_value = ($base_x / ($arraylen - 1)); Set disance between points
                        $base_y_add_value = ($base_y / 100); set distance for 1%, this will be multplied by the signal strenth later

                    ;############### Start Mapping Access Point signal Data ###############
                        SelectColor($red)
                        $base_add = 0;$base_right
                        For $o = 1 To $arraylen - 1
                            If $o <> 1 Then $base_add += $base_x_add_value
                            $base_add2 = $base_add + $base_x_add_value
                            $x1 = $base_right - $base_add
                            $x2 = $base_right - $base_add2
                            $y1 = $base_bottom - ($splitdata[$o] * $base_y_add_value)
                            $y2 = $base_bottom - ($splitdata[$o + 1] * $base_y_add_value)
                            $x3 = ($x2 - 1)
                            $x4 = ($x1 + 1)
                            SelectColor($GraphBack)
                            For $rl = $x3 To $x1
                                DrawLine($rl, $base_top, $rl, $base_bottom)
                            Next
                            SelectColor($GraphGrid)
                            For $drawline = 1 To 10
                                $subtract_value = (($drawline * 10) * $base_y_add_value)
                                DrawLine($x2, $subtract_value, $x1 + 1, $subtract_value)
                            Next
                            DrawLine($base_right, $base_top, $base_right, $base_bottom)
                            DrawLine($base_left, $base_top, $base_left, $base_bottom)
                            DrawLine($base_left, $base_top, $base_right, $base_top)

                            SelectColor($red)
                            DrawLine($x1, $y1, $x2, $y2);Draw line
                        ;Draw Dot
                            DrawLine($x1 - 1, $y1 - 1, $x1 + 1, $y1 - 1)
                            DrawLine($x1 - 1, $y1 + 1, $x1 + 1, $y1 + 1)
                            DrawLine($x1 - 1, $y1, $x1 + 1, $y1)

                        Next
                    ;############### End Mapping Access Point signal Data ###############
                    ElseIf $Graph = 2 Then
                        If $splitdata[0] > $base_x Then
                            $arraylen = $base_x
                            $base_subtract = 0
                        Else
                            $arraylen = $splitdata[0]
                            $base_subtract = $base_x - $splitdata[0]
                        EndIf
                        $base_y_add_value = ($base_y / 100); set distance for 1%, this will be multplied by the signal strenth later
                        
                        $base_add = 0
                        $base_x_add_value = 1
                        
                        For $o = 1 To $arraylen
                            $base_add += $base_x_add_value
                            If $o < $arraylen And $o <> 1 And $Redraw <> 1 Then
                                If $splitdata[$o] <> $splitdata[$o + 1] Then
                                ;MsgBox(0, $o, $arraylen)
                                    SelectColor($red)
                                    DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom, ($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value))
                                    SelectColor($GraphBack)
                                    DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value), ($base_right - $base_add) - $base_subtract, $base_top)
                                    SelectColor($GraphGrid)
                                    For $drawline = 1 To 10
                                        $subtract_value = ($drawline * 10) * $base_y_add_value
                                        DrawLine(($base_right - $base_add) - $base_subtract, $subtract_value, (($base_right - $base_add) - $base_subtract) + 1, $subtract_value)
                                    Next
                                EndIf
                            ElseIf $o = 1 Or $o = $arraylen Or $Redraw = 1 Then
                                SelectColor($red)
                                DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom, ($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value))
                                SelectColor($GraphBack)
                                DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value), ($base_right - $base_add) - $base_subtract, $base_top)
                                SelectColor($GraphGrid)
                                For $drawline = 1 To 10
                                    $subtract_value = ($drawline * 10) * $base_y_add_value
                                    DrawLine(($base_right - $base_add) - $base_subtract, $subtract_value, (($base_right - $base_add) - $base_subtract) + 1, $subtract_value)
                                Next
                            EndIf
                        Next
                        DrawLine($base_right, $base_top, $base_right, $base_bottom)
                        DrawLine($base_left, $base_top, $base_left, $base_bottom)
                        DrawLine($base_left, $base_top, $base_right, $base_top)
                    EndIf
                EndIf
                $Redraw = 0
                DrawingShutDown($GraphicGUI)
            EndIf
        EndIf
;EndIf
EndFunc  ;==>_GraphApSignal

;-------------------------------------------------------------------------------------------------------------------------------
;Graph API Functions - By neogia - http://www.autoitscript.com/forum/index.php?showtopic=24621&hl=GUICtrlSetGraphic+windows+api
;Used in place of autoit Graphic function to remove flicker when the graph gets redraw (it is slower though :-( )
;-------------------------------------------------------------------------------------------------------------------------------
Func DrawingStartUp($GUI)
    Global $gdi_dll = DllOpen("gdi32.dll"), $user32_dll = DllOpen("user32.dll")
    Global $hWnd = DllCall($user32_dll, "int", "GetDC", "hwnd", $GUI)
    $hWnd = $hWnd[0]
EndFunc  ;==>DrawingStartUp

Func DrawingShutDown($GUI)
    DllCall($user32_dll, "int", "ReleaseDC", "int", $hWnd, "hwnd", $GUI)
    DllClose($gdi_dll)
    DllClose($user32_dll)
EndFunc  ;==>DrawingShutDown

Func CreateColor($r, $G, $b)
    $hPen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00" & Hex($b, 2) & Hex($G, 2) & Hex($r, 2))
    Return $hPen[0]
EndFunc  ;==>CreateColor

Func SelectColor($hPen)
    DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $hWnd, "hwnd", $hPen)
EndFunc  ;==>SelectColor

Func DrawLine($x0, $y0, $x1, $y1)
    DllCall($gdi_dll, "int", "MoveToEx", "hwnd", $hWnd, "int", $x0, "int", $y0, "ptr", 0)
    DllCall($gdi_dll, "int", "LineTo", "hwnd", $hWnd, "int", $x1, "int", $y1)
EndFunc  ;==>DrawLine
;-------------------------------------------------------------------------------------------------------------------------------
;End Graph API functions
;-------------------------------------------------------------------------------------------------------------------------------

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

It seems to happen after ~2490 loops. I am testing to see how many lines drawn that is. I wrote control positions to a txt file, and the controls report that they are in the correct location even after they mess up.

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Well, not sure if it helps, but one bug I see is that ReleaseDC call has the params ass backwards, so the DCs aren't released.

DllCall($user32_dll, "int", "ReleaseDC", "int", $hWnd, "hwnd", $GUI)

should be

DLLCall($user32_dll, "int", "ReleaseDC", "hwnd", $GUI, "ptr", $hWnd)

window handle ($GUI) first, DC handle with a quite misinforming var name ($hWnd) second.

"be smart, drink your wine"

Link to comment
Share on other sites

Well, not sure if it helps, but one bug I see is that ReleaseDC call has the params ass backwards, so the DCs aren't released.

DllCall($user32_dll, "int", "ReleaseDC", "int", $hWnd, "hwnd", $GUI)

should be

DLLCall($user32_dll, "int", "ReleaseDC", "hwnd", $GUI, "ptr", $hWnd)

window handle ($GUI) first, DC handle with a quite misinforming var name ($hWnd) second.

I''ll let you know in 20 minutes if it helps any <_< thanks

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Can you post a screenshot of the working graph? It sounds to me like your graphing resolution far exceeds what is necessary for this program...look at the graph I made here: #426262

Each line on the graph contains only 100 segments. Thats a total of 200 segments. Even if I graphed every running process it wouldn't exceed 4000 segments.

Link to comment
Share on other sites

Can you post a screenshot of the working graph? It sounds to me like your graphing resolution far exceeds what is necessary for this program...look at the graph I made here: #426262

Each line on the graph contains only 100 segments. Thats a total of 200 segments. Even if I graphed every running process it wouldn't exceed 4000 segments.

It draws 1 line per pixel

It graphs 1 line per pixel until it reaches the graph width, then it shifts the old data off the screen[i set the array maximum to the graph width]. I have another graph thats not as many samples, but I wanted to show as much data as possible with this graph

basically if my graph is 400 pixels I am drawing 12 lines per pixel (1 for data[data %], 1 for background[remaining %], 10 for grid lines). I am drawing the background to clear old data. that hadn't been overwritten by the new data

400 x 12 = 4800 lines drawn per loop

Origionally I was drawing the 10 grid lines after it drew all the data, but i didn't like how it looked because the line would flicker

Also, to save draw time i did this:

If the data in the next array spot is the same as the data being written (array[$o] = array[$o +1]) Then it does not draw a line.(since array[$o +1] is the data that was writen to location on the last loop and it is the same as the new data being written to the spot array[$o])

post-7295-1194324211_thumb.jpg

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Simplified the example code

#include <GuiConstants.au3>
#include <Array.au3>
Global $hDC, $gdi_dll, $user32_dll
Dim $SigHist = '09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21-76-09-09-09-50-50-50-20-20-20-20-20-12-50-43-21'

Dim $sizes, $sizes_old, $data, $data_old, $Redraw = 1, $LastSelected = -1


Dim $Graphic_left
Dim $Graphic_width
Dim $Graphic_top
Dim $Graphic_height

$Vistumbler = GUICreate("MyGUI", 908, 692, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

GUISetState()
$GraphicGUI = GUICreate("", 895.72, 386.19, 10, 60, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Vistumbler)
GUISetState()
$DataChild = GUICreate("", 895, 595, 0, 60, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Vistumbler)
GUISetState()
GUISwitch($Vistumbler)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
;
    EndSelect
    $SigHist = Random(0, 100) & '-' & $SigHist
    $data = $SigHist
    _SetControlSizes()
    _GraphApSignal()
WEnd
Exit

Func _SetControlSizes()
    $a = WinGetPos($Vistumbler)
    WinMove($DataChild, "", 0, 60, $a[2] - 10, $a[3] - 115)
    $b = WinGetPos($DataChild);get child window size
    $sizes = $a[0] & '-' & $a[1] & '-' & $a[2] & '-' & $a[3] & '-' & $b[0] & '-' & $b[1] & '-' & $b[2] & '-' & $b[3]
    If $sizes <> $sizes_old Or $Redraw = 1 Then
        $Graphic_left = ($b[2] * 0.01)
        $Graphic_width = ($b[2] * 0.99) - $Graphic_left
        $Graphic_top = ($b[3] * 0.01)
        $Graphic_height = ($b[3] * 0.64) - $Graphic_top
        WinMove($GraphicGUI, "", $Graphic_left, $Graphic_top + 60, $Graphic_width, $Graphic_height)
        $sizes_old = $sizes
    EndIf
EndFunc ;==>_SetControlSizes

Func _GraphApSignal()
; If the graph tab is selected, run graph script
        If $data <> $data_old Or $sizes <> $sizes_old Or $Redraw = 1 Then; if graph data changed, map new data
            DrawingStartUp($GraphicGUI)
            $max_graph_points = 100
            $base_right = $Graphic_width - 1
            $base_left = 0
            $base_top = 0
            $base_bottom = $Graphic_height - 1
            $base_x = $base_right - $base_left
            $base_y = $base_bottom - $base_top

            $max_graph_points = 125
            $data_old = $data
            $sizes_old = $sizes
            $splitdata = StringSplit($data, '-');Split signals into an array
                
    ;Define Colors
            $GraphBack = CreateColor(215, 228, 242)
            $black = CreateColor(0, 0, 0)
            $red = CreateColor(255, 0, 0)
            $GraphGrid = CreateColor(0, 0, 255)

            If $splitdata[0] > $base_x Then
                $arraylen = $base_x
                $base_subtract = 0
            Else
                $arraylen = $splitdata[0]
                $base_subtract = $base_x - $splitdata[0]
            EndIf
            $base_y_add_value = ($base_y / 100); set distance for 1%, this will be multplied by the signal strenth later
                        
            $base_add = 0
            $base_x_add_value = 1
                        
    ;Draw Graph         
            For $o = 1 To $arraylen
                $base_add += $base_x_add_value
                If $o < $arraylen And $o <> 1 And $Redraw <> 1 Then
                    If $splitdata[$o] <> $splitdata[$o + 1] Then
                        SelectColor($red)
                        DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom, ($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value))
                        SelectColor($GraphBack)
                        DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value), ($base_right - $base_add) - $base_subtract, $base_top)
                        SelectColor($GraphGrid)
                        For $drawline = 1 To 10
                            $subtract_value = ($drawline * 10) * $base_y_add_value
                            DrawLine(($base_right - $base_add) - $base_subtract, $subtract_value, (($base_right - $base_add) - $base_subtract) + 1, $subtract_value)
                        Next
                    EndIf
                ElseIf $o = 1 Or $o = $arraylen Or $Redraw = 1 Then
                    SelectColor($red)
                    DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom, ($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value))
                    SelectColor($GraphBack)
                    DrawLine(($base_right - $base_add) - $base_subtract, $base_bottom - ($splitdata[$o] * $base_y_add_value), ($base_right - $base_add) - $base_subtract, $base_top)
                    SelectColor($GraphGrid)
                    For $drawline = 1 To 10
                        $subtract_value = ($drawline * 10) * $base_y_add_value
                        DrawLine(($base_right - $base_add) - $base_subtract, $subtract_value, (($base_right - $base_add) - $base_subtract) + 1, $subtract_value)
                    Next
                EndIf
            Next
            DrawLine($base_right, $base_top, $base_right, $base_bottom)
            DrawLine($base_left, $base_top, $base_left, $base_bottom)
            DrawLine($base_left, $base_top, $base_right, $base_top)
            $Redraw = 0
            DrawingShutDown($GraphicGUI)
        EndIf
EndFunc ;==>_GraphApSignal

;-------------------------------------------------------------------------------------------------------------------------------
;Graph API Functions - By neogia - http://www.autoitscript.com/forum/index.php?showtopic=24621&hl=GUICtrlSetGraphic+windows+api
;Used in place of autoit Graphic function to remove flicker when the graph gets redraw (it is slower though :-( )
;-------------------------------------------------------------------------------------------------------------------------------
    Func DrawingStartUp($GUI)
        Global $gdi_dll = DllOpen("gdi32.dll"), $user32_dll = DllOpen("user32.dll")
        Global $hDC = DllCall($user32_dll, "int", "GetDC", "hwnd", $GUI)
        $hDC = $hDC[0]
    EndFunc ;==>DrawingStartUp

    Func DrawingShutDown($GUI)
        DLLCall($user32_dll, "int", "ReleaseDC", "hwnd", $GUI, "ptr", $hDC)
;DllCall($user32_dll, "int", "ReleaseDC", "int", $hDC, "hwnd", $GUI)
        DllClose($gdi_dll)
        DllClose($user32_dll)
    EndFunc ;==>DrawingShutDown

    Func CreateColor($r, $G, $b)
        $hPen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00" & Hex($b, 2) & Hex($G, 2) & Hex($r, 2))
        Return $hPen[0]
    EndFunc ;==>CreateColor

    Func SelectColor($hPen)
        DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hPen)
    EndFunc ;==>SelectColor

    Func DrawLine($x0, $y0, $x1, $y1)
        DllCall($gdi_dll, "int", "MoveToEx", "hwnd", $hDC, "int", $x0, "int", $y0, "ptr", 0)
        DllCall($gdi_dll, "int", "LineTo", "hwnd", $hDC, "int", $x1, "int", $y1)
    EndFunc ;==>DrawLine
;-------------------------------------------------------------------------------------------------------------------------------
;End Graph API functions
;-------------------------------------------------------------------------------------------------------------------------------
Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

From what I am reading about DCs it seems likely that I am still not Releasing the DCs properly.

-Common DCs come from a Windows cache of limited size!

A program should release a DC when it's done using it, or disastrous

things could happen!

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

This problem is kind of tough to test. You say it happens after 20 minutes or 2500 loops, and using your latest example on my oldie PC, in 5 minutes it did 200 loops so it would take much longer.

Anyway.

You can check the return value of these functions, ReleaseDC returns nonzero on success.

Another potential problem I see is that creation of 4 pens (colors) each loop. Each created object has to be deleted with DeleteObject when not needed anymore, if you want to play safe. Now, even though this happens inside a function, I'm not sure AutoIt is smart enough to clean it up for you by automatically deleting GDI objects referenced by local variables (I know it does clean up internal things, such as DllStructs, but that may be a different story). Even if it did, the currently selected object can't be deleted without deselecting it first, and one of the colors stays selected after a loop, so even in best case you have 1 object handle leak each loop (after you create another 4 pens and select one of them, leaving the previously selected in limbo). Worst case - 4 handles.

Bottom line is that you don't even need to (re)create them inside the loop, given that these 4 colors stay constant. Move them at the top of your script where other global variabless are.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Ok, it seems to me that what I wrote above is indeed your problem.

Just ran it in the background with the suggested changes, and it drawns fine after 2500.

Move this

;Define Colors
            $GraphBack = CreateColor(215, 228, 242)
            $black = CreateColor(0, 0, 0)
            $red = CreateColor(255, 0, 0)
            $GraphGrid = CreateColor(0, 0, 255)

from the function to the top of the script, and also fix DllCall in CreateColor() accordingly, "DllCall('gdi32.dll'," instead of "DllCall($gdi_dll,...".

It seems that there's a limit on GDI objects per session, 10000 according to some google sources. So when you're creating 4 objects each loop and deleting none, ~2500 here's your magic number <_<

As a bonus, it also made the drawing significantly faster, at least for me.

Also you might want to delete these pens with DeleteObject() when exiting your script, just to be nice.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Awsome Siao :-) I will test this tonight. Thank you for your help and testing :-)

This is the first time i have ever drawn anything with the windows API, so its all new information to me :-).

WeaponX is right...you definatly went above and beyond :-).

P.S. weaponx, the demo script i made should not need vista, but thank you for all your input in this thred also :-)

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

also fix DllCall in CreateColor() accordingly, "DllCall('gdi32.dll'," instead of "DllCall($gdi_dll,...".

Why do you suggest doing this, from a quick look at the DllCall example it seems like that is correct. (but what do I know about dllcalls <_< )

From the AutoIt help file

$dll = DllOpen("user32.dll")
$result = DllCall($dll, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
DllClose($dll)

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...