STARGÅTE wrote: Thu Nov 10, 2022 6:26 am
An "invalid memory access" not always relates to the function where it occurs.
For example, when CloseWindow() is called, also all the gadgets, menus, times, toolbars, bound events etc. are freed.
So it is likely that the error has another reason, long before the window is closed.
Try to use the Purifier, to determine memory overflows.
Its probably something related to this, the problem is that is totally random, i dont know exactly what is causeing the issue. I enabled purefier but amybe im not able to understand how to work with it or i dont have any memory overflow as its not reporting anything.
Im going to paste the total code where the close window is called maybe someone is able to see anything im not seeing, but i dont know how usefull it would be without the rest of the code
Code: Select all
Procedure updateMap()
Shared folderSelectedID
Shared mapFiles()
Shared MapTileIDSelctedArr()
Shared mapLowerIMGSBack()
Shared mapUpperIMGSBack()
SelectElement(globalListMaps(),folderSelectedID)
SelectElement(mapFiles(),globalListMaps()\fileData)
globalListMaps()\file = GetGadgetText(#nameEditMap)
actualX.i = mapFiles()\sizeX
actualY.i = mapFiles()\sizeY
newX.i = Val(GetGadgetText(#sizeXEditMap))
newY.i = Val(GetGadgetText(#sizeYEditMap))
chipsetAct.i = mapFiles()\chipset
chipsetNew.i = GetGadgetState(#chipsetListEditMap)
;Debug "act : " + Str(chipsetAct) + " new: "+Str(chipsetnew)
Debug "Updating map"
If Not actualX = newX Or Not actualY = newY
mapFiles()\sizeX = newX
mapFiles()\sizeY = newY
; NewList mapUpperIMGSaux.mapTile()
; NewList mapLowerIMGSaux.mapTile()
NewList layerGroupsAux.layerGroup()
counter = 0
ForEach globalListLayerG()
If counter = 0
AddElement(layerGroupsAux())
createMapEx(layerGroupsAux()\layer(),0,newX,newY)
Else
AddElement(layerGroupsAux())
createMapEx(layerGroupsAux()\layer(),1,newX,newY)
EndIf
counter = counter + 1
Next
; For i = 1 To 4
; AddElement(layerGroupsAux())
; createMapEx(layerGroupsAux()\layer(),1,newX,newY)
; Next
Debug "Maps created Ex"
;createMap(mapLowerIMGSaux(),mapUpperIMGSaux(),newX,newY)
sizeSelX = Min(actualX, newX)
sizeSelY = Min(actualY, newY)
NewList layerCopy.sArray2()
layercount = 0
ForEach mapFiles()\layerGroups()
Debug "creating layer: " + Str(layercount)
layercount = layercount + 1
AddElement(layerCopy())
Dim layerCopy()\arr(sizeSelX-1,sizeSelY-1)
For i = 0 To ArraySize(layerCopy()\arr(),2)
For z = 0 To ArraySize(layerCopy()\arr(),1)
idsel = (mapSelectYini+i) * actualX
idsel = idsel + mapSelectXini+z
SelectElement(mapFiles()\layerGroups()\layer(),idsel)
layerCopy()\arr(z,i) = mapFiles()\layerGroups()\layer()\intelliID
Next z
Next i
Next
SelectElement(layerGroupsAux(),0)
Debug "drawing tiles"
Debug "finished tileS"
counter = 0
ForEach layerCopy()
For i = 0 To ArraySize(layerCopy()\arr(),2)
For z = 0 To ArraySize(layerCopy()\arr(),1)
SelectElement(layerGroupsAux(),counter)
drawMapTileFinal(z,i,1,layerCopy()\arr(z,i),layerGroupsAux()\layer())
;drawMapTileFinal(z,i,1,MapTileIDSelctedArrUpper(z,i),mapUpperIMGSaux())
Next z
Next i
counter = counter +1
Next
Debug "layer copy created"
counter = 0
ForEach layerGroupsAux()
SelectElement(mapFiles()\layerGroups(),counter)
CopyList(layerGroupsAux()\layer(),mapFiles()\layerGroups()\layer())
counter = counter +1
Next
Debug "LAyer copy copied"
refreshMap()
;
EndIf
If Not chipsetAct = chipsetNew And chipsetNew >= 0
Debug "updating chipsets"
mapFiles()\chipset = chipsetNew
loadChipset(mapFiles()\chipset)
refreshMap()
selectingMapZoom(globalZoomMap)
Debug "chipsets updated"
EndIf
folderRefresh()
Debug "folder refreshed"
DisableWindow(#mainWindow,#False)
Debug "enabling window"
Delay(1000)
Debug "after delay"
If IsWindow(#editMapWindow)
CloseWindow(#editMapWindow)
EndIf
EndProcedure
All the debug messages are triggered without any issue and still crash in the closewindow
This is the code that creates the window
Code: Select all
Procedure editMapWindow(mode.i = 0)
Shared folderSelectedID
Shared mapFiles()
Shared mapNextID
SelectElement(globalListMaps(),folderSelectedID)
SelectElement(mapFiles(),globalListMaps()\fileData)
DisableWindow(#mainWindow,#True)
editMap.s = "Edit Map"
applyChanges.s = "Apply Changes"
nameTxt.s = globalListMaps()\file
If mode = 1
editMap = "Create Map"
nameTxt = "map_" + Str(mapNextID+1)
EndIf
If OpenWindow(#editMapWindow,0,0,400,400,editMap,#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
StickyWindow(#editMapWindow,#True)
displacementY.i = 10
displacementX.i = 50
TextGadget(#PB_Any, 10, displacementY, displacementX, 24, "Name")
StringGadget(#nameEditMap, displacementX+10, displacementY, 200, 24, nameTxt)
displacementY = displacementY + 26
TextGadget(#PB_Any, 10, displacementY, displacementX, 24, "Size X")
StringGadget(#sizeXEditMap, displacementX+10, displacementY, 200, 24, Str(mapFiles()\sizeX))
displacementY = displacementY + 26
TextGadget(#PB_Any, 10, displacementY, displacementX, 24, "Size Y")
StringGadget(#sizeYEditMap, displacementX+10, displacementY, 200, 24, Str(mapFiles()\sizeY))
displacementY = displacementY + 36
TreeGadget(#chipsetListEditMap, 10, displacementY, 120, 200)
Define RowHeight.CGFloat
CocoaMessage(@RowHeight, GadgetID(#chipsetListEditMap), "rowHeight")
RowHeight = 17.0
CocoaMessage(0, GadgetID(#chipsetListEditMap), "setRowHeight:@", @RowHeight)
ForEach globalChipsetAssets()
AddGadgetItem(#chipsetListEditMap,-1,globalChipsetAssets()\name)
Next
SetGadgetState(#chipsetListEditMap,mapFiles()\chipset)
CanvasGadget(#chipsetCanvasEditMap, 140, displacementY, 250, 200)
SelectElement(globalChipsetAssets(),mapFiles()\chipset)
editMapRefresh(globalChipsetAssets()\img)
displacementY = displacementY + 200 + 15
Select mode
Case 0:
ButtonGadget(#applyButtonEditMap, 10, displacementY, 160, 34, "Apply Changes")
Case 1
ButtonGadget(#createNewmapEditMap, 10, displacementY, 160, 34, "Accept")
EndSelect
EndIf
EndProcedure