in my opinion, there is a bug with UpdateTerrainTileLayerBlend(). When you start my first code, there is no memory access error.
In the first code, the terraintexture will changed in the Y-direction. No error occures, the code is running perfectly.
But if you try to run the second code, an memory access error occures. Always on the 2. layer (No. 1) and always at the first cycle of the pyramided For:Next at the end of the code.
The only thing different is that in the second code the terraintexture will changed in X-direction.
PB 5.11, Win XP SP3
EDIT: You can choose any pictures you have for the terraintextures.
Code 1:
Code: Select all
EnableExplicit
;teilX = Tile in X direction
;teilY = Tile in Y direction
;stelle = point where the "action" is; in world units
;_________________
;| | |
;| 1/1 | 1/0 |
;| | |
;|_______|_______|
;| | |
;| 0/1 | 0/0 |
;| | |
;|_______|_______|
Structure Vektor3
x.f
y.f
z.f
EndStructure
Global.i terrain, terrainX, terrainY, teilX, teilY, h, X, Y
Global.Vektor3 stelle
Global.f blendWert, ttpointy, ttpointx
#G_Heightmap = 513
#layerAnzahl = 2
#skalFaktor = 5
#weltGroesse = 2
Enumeration
#Licht_0
EndEnumeration
InitEngine3D()
InitSprite()
OpenScreen(1920, 1080, 32, "Test_Blend_0", #PB_Screen_SmartSynchronization)
;- Licht
CreateLight(#Licht_0 ,RGB(190, 190, 190), 500, 500, 500, #PB_Light_Point)
SetLightColor(#Licht_0, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
;- Terrain Definition
SetupTerrains(LightID(#Licht_0), 10, #PB_Terrain_NormalMapping)
terrain = CreateTerrain(#PB_Any, #G_Heightmap, 100, #skalFaktor, #layerAnzahl, "terrain", "Dat")
AddTerrainTexture(terrain, 0, 1, "Gras_0.png", "Gras_0_Normal.png") ;-Terraintexturen
AddTerrainTexture(terrain, 1, 1, "Steinstrasse_0_1.png", "Steinstrasse_0_1_Normal.png")
TerrainLocate(terrain, 50, 0, 50 + 100 * (#weltGroesse - 1)) ;Gesamtes Terrain wird so positioniert, dass die linke untere Ecke auf 0/0 liegt.
For terrainX = 0 To #weltGroesse - 1
For terrainY = 0 To #weltGroesse - 1
DefineTerrainTile(terrain, terrainX, terrainY, "heightmap.png", #False, #False)
Next
Next
BuildTerrain(terrain)
teilX = 0
teilY = 1
stelle\x = 50
stelle\z = 99.99
stelle\y = TerrainHeight(terrain, stelle\x, stelle\z)
ttpointx = TerrainTilePointX(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
ttpointy = TerrainTilePointY(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
For h = 0 To #layerAnzahl - 1 ;1024, weil die LayerBlendmapgröße 1024 beträgt.
blendWert = GetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024)
If blendWert = 1
SetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024, 0.0)
EndIf
Next
SetTerrainTileLayerBlend(terrain, teilX, teilY, 1, ttpointx * 1024, 1024 - ttpointy * 1024, 1.0)
teilX = 0
teilY = 0
stelle\x = 50
stelle\z = 100.01
stelle\y = TerrainHeight(terrain, stelle\x, stelle\z)
ttpointx = TerrainTilePointX(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
ttpointy = TerrainTilePointY(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
For h = 0 To #layerAnzahl - 1 ;1024, weil die LayerBlendmapgröße 1024 beträgt.
blendWert = GetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024)
If blendWert = 1
SetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024, 0.0)
EndIf
Next
SetTerrainTileLayerBlend(terrain, teilX, teilY, 1, ttpointx * 1024, 1024 - ttpointy * 1024, 1.0)
For X = 0 To 1
For Y = 1 To 0 Step -1
Debug Str(X) + "..." + Str(Y)
UpdateTerrainTileLayerBlend(terrain, X, Y, 1) ;-<-- Error, Speicheradresse blablabla.
UpdateTerrainTileLayerBlend(terrain, X, Y, 0)
Next Y
Next X
End
Code: Select all
EnableExplicit
Structure Vektor3
x.f
y.f
z.f
EndStructure
Global.i terrain, terrainX, terrainY, teilX, teilY, h, X, Y
Global.Vektor3 stelle
Global.f blendWert, ttpointy, ttpointx
#G_Heightmap = 513
#layerAnzahl = 2
#skalFaktor = 5
#weltGroesse = 2
Enumeration
#Licht_0
EndEnumeration
InitEngine3D()
InitSprite()
OpenScreen(1920, 1080, 32, "Test_Blend_0", #PB_Screen_SmartSynchronization)
;- Licht
CreateLight(#Licht_0 ,RGB(190, 190, 190), 500, 500, 500, #PB_Light_Point)
SetLightColor(#Licht_0, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
;- Terrain Definition
SetupTerrains(LightID(#Licht_0), 10, #PB_Terrain_NormalMapping)
terrain = CreateTerrain(#PB_Any, #G_Heightmap, 100, #skalFaktor, #layerAnzahl, "terrain", "Dat")
AddTerrainTexture(terrain, 0, 1, "Gras_0.png", "Gras_0_Normal.png") ;-Terraintexturen
AddTerrainTexture(terrain, 1, 1, "Steinstrasse_0_1.png", "Steinstrasse_0_1_Normal.png")
TerrainLocate(terrain, 50, 0, 50 + 100 * (#weltGroesse - 1)) ;Gesamtes Terrain wird so positioniert, dass die linke untere Ecke auf 0/0 liegt.
For terrainX = 0 To #weltGroesse - 1
For terrainY = 0 To #weltGroesse - 1
DefineTerrainTile(terrain, terrainX, terrainY, "heightmap.png", #False, #False)
Next
Next
BuildTerrain(terrain)
teilX = 0
teilY = 1
stelle\z = 50
stelle\x = 99.99
stelle\y = TerrainHeight(terrain, stelle\x, stelle\z)
ttpointx = TerrainTilePointX(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
ttpointy = TerrainTilePointY(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
For h = 0 To #layerAnzahl - 1 ;1024, weil die LayerBlendmapgröße 1024 beträgt.
blendWert = GetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024)
If blendWert = 1
SetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024, 0.0)
EndIf
Next
SetTerrainTileLayerBlend(terrain, teilX, teilY, 1, ttpointx * 1024, 1024 - ttpointy * 1024, 1.0)
teilX = 1
teilY = 1
stelle\z = 50
stelle\x = 100.01
stelle\y = TerrainHeight(terrain, stelle\x, stelle\z)
ttpointx = TerrainTilePointX(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
ttpointy = TerrainTilePointY(terrain, teilX, teilY, stelle\x, stelle\y, stelle\z)
For h = 0 To #layerAnzahl - 1 ;1024, weil die LayerBlendmapgröße 1024 beträgt.
blendWert = GetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024)
If blendWert = 1
SetTerrainTileLayerBlend(terrain, teilX, teilY, h, ttpointx * 1024, 1024 - ttpointy * 1024, 0.0)
EndIf
Next
SetTerrainTileLayerBlend(terrain, teilX, teilY, 1, ttpointx * 1024, 1024 - ttpointy * 1024, 1.0)
For X = 0 To 1
For Y = 1 To 0 Step -1
Debug Str(X) + "..." + Str(Y)
UpdateTerrainTileLayerBlend(terrain, X, Y, 1) ;-<-- Error, Speicheradresse blablabla.
UpdateTerrainTileLayerBlend(terrain, X, Y, 0)
Next Y
Next X
End
Bananenfreak

