HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

wtf critical error with RegionAddCell ...

04-06-2008, 11:05 AM#1
Troll-Brain
I got a critical error (the memory could not be read ...) when i use the function RegionAddCell but i can't guess why ...
That's strange because in the second loop it works fine but not in the first

Here is the code :

Collapse JASS:
function Circle2Reg takes real xC,real yC,real radius returns region

local real xR=SquareRoot(2)*radius/2.0
local real xMin=R2I((xC-xR)/32.0)*32.0
local real yMin=R2I((yC-xR)/32.0)*32.0
local real xMax=R2I((xC+xR)/32.0)*32.0
local real yMax=R2I((yC+xR)/32.0)*32.0
local real x=xMin-32.0
local real y
local region reg=CreateRegion()


    loop
    set x=x+32.0
        set y=R2I( yC + SquareRoot( (radius*radius) - (x-xC)*(x-xC) ) )*32.0
        //call RegionAddCell(reg,x,y)
        set y=R2I( yC - SquareRoot( (radius*radius) - (x-xC)*(x-xC) ) )*32.0
        //call RegionAddCell(reg,x,y)
    exitwhen x==xMax
    endloop
  
  set y=yMin-32.0
    
    loop
    set y=y+32.0
        set x=R2I( xC + SquareRoot( (radius*radius) - (y-yC)*(y-yC) ) )*32.0
        call RegionAddCell(reg,x,y)
        set x=R2I( xC - SquareRoot( (radius*radius) - (y-yC)*(y-yC) ) )*32.0
        call RegionAddCell(reg,x,y)
    exitwhen y==yMax
    endloop   
    
   return reg

endfunction

if i uncomment one of the RegionAddCell in the first loop i got an error.

Here is a test map if you want :
Just uncomment the lines in the custom code and press escape in the game

EDIT : Hmm it seems the function is not correct the cells are out the playable map area, that's probably why warcraft3 crash
04-06-2008, 11:40 AM#2
PitzerMike
May be an endless loop.

Try
Collapse JASS:
exitwhen x>=xMax

== can be tricky on reals.

EDIT: Oh wait, the loop works without the RegionAddCell calls.
My bad...
04-06-2008, 12:02 PM#3
Vexorian
Make sure the point is inside the map's bounds.
04-06-2008, 12:45 PM#4
Troll-Brain
Quote:
Originally Posted by Vexorian
Make sure the point is inside the map's bounds.
yes it's outside that's why war3 crash.
sorry but i was pretty sure for the function ...