Tracking infamous GetTileFromHDD bug
hanging sometimes don't know why.
This commit is contained in:
46
PBMap.pb
46
PBMap.pb
@@ -25,7 +25,7 @@ UsePNGImageEncoder()
|
|||||||
|
|
||||||
DeclareModule PBMap
|
DeclareModule PBMap
|
||||||
;-Show debug infos
|
;-Show debug infos
|
||||||
Global Verbose = #false
|
Global Verbose = #False
|
||||||
Global MyDebugLevel = 3
|
Global MyDebugLevel = 3
|
||||||
Global Proxy = #False
|
Global Proxy = #False
|
||||||
Declare InitPBMap()
|
Declare InitPBMap()
|
||||||
@@ -156,7 +156,9 @@ Module PBMap
|
|||||||
Options.option ;
|
Options.option ;
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
|
;-Global variables
|
||||||
Global PBMap.PBMap, Null.i
|
Global PBMap.PBMap, Null.i
|
||||||
|
Global LoadMutexTest = CreateMutex()
|
||||||
|
|
||||||
;Shows an error msg and terminates the program
|
;Shows an error msg and terminates the program
|
||||||
Procedure Error(msg.s)
|
Procedure Error(msg.s)
|
||||||
@@ -168,6 +170,7 @@ Module PBMap
|
|||||||
Procedure MyDebug(msg.s, DbgLevel = 0)
|
Procedure MyDebug(msg.s, DbgLevel = 0)
|
||||||
If Verbose And MyDebugLevel >= DbgLevel
|
If Verbose And MyDebugLevel >= DbgLevel
|
||||||
PrintN(msg)
|
PrintN(msg)
|
||||||
|
;Debug msg
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -289,21 +292,33 @@ Module PBMap
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Quit()
|
Procedure Quit()
|
||||||
;Ask main drawing thread to stop and wait for it (nicer than KillThread(PBMap\MainDrawingThread))
|
Protected TimeCounter.q
|
||||||
|
;Ask main drawing thread to stop and wait for it for 2 seconds
|
||||||
LockMutex(PBMap\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
PBMap\Drawing\End = #True
|
PBMap\Drawing\End = #True
|
||||||
UnlockMutex(PBMap\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
Repeat : Until Not IsThread(PBMap\MainDrawingThread)
|
TimeCounter = ElapsedMilliseconds()
|
||||||
;Wait for loading threads to finish nicely
|
Repeat
|
||||||
|
Delay(100)
|
||||||
|
If ElapsedMilliseconds() - TimeCounter > 2000
|
||||||
|
;Should not occur
|
||||||
|
KillThread(PBMap\MainDrawingThread)
|
||||||
|
EndIf
|
||||||
|
Until Not IsThread(PBMap\MainDrawingThread)
|
||||||
|
;Wait for loading threads to finish nicely. Passed 2 seconds, kills them.
|
||||||
|
TimeCounter = ElapsedMilliseconds()
|
||||||
Repeat
|
Repeat
|
||||||
ResetList(PBMap\TilesThreads())
|
ResetList(PBMap\TilesThreads())
|
||||||
While NextElement(PBMap\TilesThreads())
|
While NextElement(PBMap\TilesThreads())
|
||||||
If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
|
If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
|
||||||
FreeMemory(PBMap\TilesThreads()\Tile)
|
FreeMemory(PBMap\TilesThreads()\Tile)
|
||||||
DeleteElement(PBMap\TilesThreads())
|
DeleteElement(PBMap\TilesThreads())
|
||||||
|
ElseIf ElapsedMilliseconds() - TimeCounter > 2000
|
||||||
|
;Should not occur
|
||||||
|
KillThread(PBMap\TilesThreads()\GetImageThread)
|
||||||
EndIf
|
EndIf
|
||||||
Wend
|
Wend
|
||||||
Delay(20)
|
Delay(10)
|
||||||
Until ListSize(PBMap\TilesThreads()) = 0
|
Until ListSize(PBMap\TilesThreads()) = 0
|
||||||
curl_global_cleanup()
|
curl_global_cleanup()
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -435,14 +450,21 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure.i GetTileFromHDD(CacheFile.s)
|
Procedure.i GetTileFromHDD(CacheFile.s)
|
||||||
Protected nImage.i
|
Protected nImage.i
|
||||||
|
Debug "Loading image " + CacheFile + " ; Size : " + Str(FileSize(CacheFile))
|
||||||
If FileSize(CacheFile) > 0
|
If FileSize(CacheFile) > 0
|
||||||
nImage = LoadImage(#PB_Any, CacheFile)
|
nImage = LoadImage(#PB_Any, CacheFile)
|
||||||
If IsImage(nImage)
|
If IsImage(nImage)
|
||||||
MyDebug("Loadimage " + CacheFile + " -> Success !", 3)
|
Debug "Success loading " + CacheFile + " as nImage " + Str(nImage)
|
||||||
|
MyDebug("Success loading " + CacheFile + " as nImage " + Str(nImage), 3)
|
||||||
ProcedureReturn nImage
|
ProcedureReturn nImage
|
||||||
|
Else
|
||||||
|
Debug "Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !"
|
||||||
|
MyDebug("Failed loading " + CacheFile + " as nImage " + Str(nImage) + " -> not an image !", 3)
|
||||||
EndIf
|
EndIf
|
||||||
|
Else
|
||||||
|
Debug "Failed loading " + CacheFile + " -> Size = 0"
|
||||||
|
MyDebug("Failed loading " + CacheFile + " -> Size = 0", 3)
|
||||||
EndIf
|
EndIf
|
||||||
MyDebug("Loadimage " + CacheFile + " -> Failed !", 3)
|
|
||||||
ProcedureReturn -1
|
ProcedureReturn -1
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -485,7 +507,9 @@ Module PBMap
|
|||||||
Protected Tile.position
|
Protected Tile.position
|
||||||
; PBMap\MemCache\Images(*Tile\key)\Mutex = CreateMutex()
|
; PBMap\MemCache\Images(*Tile\key)\Mutex = CreateMutex()
|
||||||
; LockMutex(PBMap\MemCache\Images(*Tile\key)\Mutex)
|
; LockMutex(PBMap\MemCache\Images(*Tile\key)\Mutex)
|
||||||
|
; LockMutex(LoadMutexTest)
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
nImage = GetTileFromHDD(CacheFile)
|
||||||
|
; UnlockMutex(LoadMutexTest)
|
||||||
If nImage = -1
|
If nImage = -1
|
||||||
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile)
|
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile)
|
||||||
If nImage = -1
|
If nImage = -1
|
||||||
@@ -570,6 +594,7 @@ Module PBMap
|
|||||||
MyDebug(" Creating get image thread nb " + Str(\GetImageThread), 2)
|
MyDebug(" Creating get image thread nb " + Str(\GetImageThread), 2)
|
||||||
Else
|
Else
|
||||||
MyDebug(" Can't add a new image to the map list", 2)
|
MyDebug(" Can't add a new image to the map list", 2)
|
||||||
|
CallDebugger
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
If IsImage(\nImage)
|
If IsImage(\nImage)
|
||||||
@@ -774,7 +799,7 @@ Module PBMap
|
|||||||
VectorSourceColor(RGBA(0, 0, 0, 80))
|
VectorSourceColor(RGBA(0, 0, 0, 80))
|
||||||
MovePathCursor(50,50)
|
MovePathCursor(50,50)
|
||||||
DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
|
DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
|
||||||
MovePathCursor(50,60)
|
MovePathCursor(50,80)
|
||||||
DrawVectorText(Str(ListSize(PBMap\TilesThreads())))
|
DrawVectorText(Str(ListSize(PBMap\TilesThreads())))
|
||||||
StopVectorDrawing()
|
StopVectorDrawing()
|
||||||
;Redraw
|
;Redraw
|
||||||
@@ -1191,9 +1216,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
EndIf
|
EndIf
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; ExecutableFormat = Console
|
; CursorPosition = 450
|
||||||
; CursorPosition = 305
|
; FirstLine = 444
|
||||||
; FirstLine = 278
|
|
||||||
; Folding = ---------
|
; Folding = ---------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user