Jump to content

Clicking the area of a deleted Pic control crashes program


Recommended Posts

Right now I'm developing a program that deals with TCP connections and Picture controls, but for some reason it periodically will crash. There is nothing consistant, and I can't tell what is causing the crash, but it only occurs if I click the window, but only crashes sometimes.

If anyone has had a similar problems, I'd be shocked but grateful for any advice.

Otherwise, are there any debugging tools that can display information about the crash?

EDIT: So I've figured out what is causing the crash. If I click on the region where there was a Pic control (that was deleted) it crashes. When I delete the pic, I set the variable to 0 to be on the safe side but this still happens. Any thoughts?

Edited by JFee

Regards,Josh

Link to comment
Share on other sites

Bump...

Right now I have a temporary fix for the problem. Instead of deleting the pic right away, I hide it until another one has to be made, then I delete and immediately create again. This works fine, but it is still bothering me why it would be doing this

Regards,Josh

Link to comment
Share on other sites

@try67... no event. I'm not using GUIOnEventMode, and there is nothing in my GUIMsg loop that involves it.

@larry... I really wish I could. I just tried to again, but nothing I do can recreate it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Include <String.au3>
#include <WinAPI.au3>

Global $imageFile = @WorkingDir & "\image.bmp"
Global $imageFile2 = @WorkingDir & "\image2.bmp"
Global $imageExists = 0
Global $picImage, $currentImage

$mainGUI = GUICreate("Bug", 800, 600, 0, 0)
GUISetBkColor(0x000000)
GUISetCursor(16)
GUISetState()

$toggleButton1 = GUICtrlCreateButton("Toggle", 10, 10)
$toggleButton2 = GUICtrlCreateButton("Toggle2", 10, 60)

While 1
    
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $toggleButton1
            toggleImage($imageFile)
        Case $msg = $toggleButton2
            toggleImage($imageFile2)
    EndSelect
WEnd

Exit

Func toggleImage($imageLocation)
    
    If $currentImage = $imageLocation Then
        GUICtrlDelete($picImage)
        $currentImage = ""
    ElseIf $currentImage = "" Then
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromFile($imageLocation)
        $tImageWidth = _GDIPlus_ImageGetWidth($hImage)
        $tImageHeight = _GDIPlus_ImageGetHeight($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $tPosX = 400 - $tImageWidth / 2
        $tPosY = 600 - $tImageHeight; - $offset
        
        $picImage = GUICtrlCreatePic($imageLocation, $tPosX, $tPosY, $tImageWidth, $tImageHeight)
        GUICtrlSetState(-1, $GUI_DISABLE)
        $currentImage = $imageLocation

    Else

        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromFile($imageLocation)
        $tImageWidth = _GDIPlus_ImageGetWidth($hImage)
        $tImageHeight = _GDIPlus_ImageGetHeight($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $tPosX = 400 - $tImageWidth / 2
        $tPosY = 600 - $tImageHeight; - $offset
        
        GUICtrlDelete($picImage)
        $picImage = GUICtrlCreatePic($imageLocation, $tPosX, $tPosY, $tImageWidth, $tImageHeight)
        GUICtrlSetState(-1, $GUI_DISABLE)
        $currentImage = $imageLocation
    EndIf
    
EndFunc

Throw a couple of images into wherever you run the script from...

That is the short code that doesn't have the problem, but it should because the window is created the same way. Only difference is that in my full program, instead of clicking a button there is a select case of TCP messages instead of GUI messages.

Edit: I'm using Vista and XP for development (problem on both). Not sure about version.... I downloaded the newest version a week or two ago

Edited by JFee

Regards,Josh

Link to comment
Share on other sites

OK... well here is a stickler on this subject. Any script that uses functions not native to AutoIt (via DLLCall) is subject to the attention of whomever wrote the UDF (User Defined Function). Find the author of the _GDIPlus stuff and seek that entity's council first. If there is a consensus therein that the DLLCall() function is not handling something... write up a bug.

Lar.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

Correction: Only happens on Vista. I just tried it on my XP machine and no problem.

Also, it can't be _GDIPlus because I only use it to determine the image's width and height... I don't create actually use it to create the image.

Going back to my original post... are there any programs or anything that can help me debug this? If I had basic information about the crash I could know where to start looking.

Regards,Josh

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...