← Back to team overview

mudlet-makers team mailing list archive

Re: [Bug 1226558] [NEW] getRoom in TArea causes seg fault on map creation

 

You're correct that 0 can be used as the placeholder. All areas start at 1
(now at least). If this is historically true, it is a valid choice.  I
don't think an all-in-one is a good idea personally since it makes us less
modular in the future.


On Wed, Sep 18, 2013 at 5:07 PM, Stephen Lyons
<1226558@xxxxxxxxxxxxxxxxxx>wrote:

> On 17/09/13 23:59, Vadim Peretokin wrote:
> > Yeah I agree. We should be able to create rooms, not have to place them
> > into an area - setup their properties and then add it to one.
> >
>
>     Ah, I recently was adding some rooms to an old map to test some
> mapping code.  I had an empty area and although through the LUA
> interface all the rooms seem to be in that area, the map drawing code
> was treating some as being out of the area and not drawing exits/routes
> between them properly when I added them later - the problem did not seem
> to be fixed until after the map was saved and reloaded.  I'd like to
> know what was wrong (if anything).  At a wild guess I'd say that some
> structures are not being amended with new data as rooms are added.  I
> vaguely recall that some of the mapping data (the levels or "ebenung"?
> tables) may not be being updated as rooms are inserted/deleted.
>
>     I added into my code a LUA function to create a room (with the next
> available RoomID) in an area with given areaID, coordinates and room
> name but am I missing something in the room creation process?
>
>     Also, do we not have an area with ID = 0 that always exists - would
> it be safe to use that as an implicitly unnamed or default area (perhaps
> it should have a fixed name of something like "_unnamed" so that it
> always(?) is the first area in the mapper area selection list?)  I can't
> recall whether that area is actually displayable as a map anyway?  If it
> was would this still be problematic for inexperienced users starting out
> building a fresh map and then wanting to name the first area they
> created if they tried to rename such a default (un-renameable) area
> rather than using the GUI or LUA code to move their rooms en-block to a
> new area?
>
>     I must check also whether it is allowed to add a room to an area
> without giving any coordinates - I guess if it *is* you get a load of
> rooms piling up at (0,0,0) which can be awkward to sort out later... 8-)
>
>
>     Possible all-in-one room creation LUA function:
> (Header file and LUA function registration not shown):
> // createRoom( AreaID, RoomName, x, y, z )
> // Returns new room ID, or nil on failure
> // Convenience function to make a NEW room in a given area
> int TLuaInterpreter::createRoom( lua_State *L )
> {
>     int areaId, x, y, z;
>     Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
>     string name;
>     TArea * pA;
>
>     if(! pHost || ! pHost->mpMap || ! pHost->mpMap->mpRoomDB)
>     {
>         lua_pushstring( L, "createRoom: internal failure" );
>         lua_error( L );
>         return 1;
>     }
>
>     if( lua_isnumber( L, 1 ) )
>     {
>         areaId = lua_tonumber( L, 1 );
>         pA = pHost->mpMap->mpRoomDB->getArea( areaId );
>         if( !pA )
>         {
>             lua_pushstring( L, "createRoom: invalid areaId value" );
>             lua_error( L );
>             return 1;
>         }
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: wrong argument(1) type" );
>         lua_error( L );
>         return 1;
>     }
>
>     if( lua_isstring( L, 2 ) )
>     {
>         name = lua_tostring( L, 2 );
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: wrong argument(2) type" );
>         lua_error( L );
>         return 1;
>     }
>
>     if( lua_isnumber( L, 3 ) )
>     {
>         x = lua_tonumber( L, 3);
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: wrong argument(3) type" );
>         lua_error( L );
>         return 1;
>     }
>
>     if( lua_isnumber( L, 4 ) )
>     {
>         y = lua_tonumber( L, 4);
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: wrong argument(4) type" );
>         lua_error( L );
>         return 1;
>     }
>
>     if( lua_isnumber( L, 5 ) )
>     {
>         z = lua_tonumber( L, 5);
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: wrong argument(5) type" );
>         lua_error( L );
>         return 1;
>     }
>
>     int id = pHost->mpMap->createNewRoomID();
>
>     if( pHost->mpMap->addRoom( id ) )
>     {
>         TRoom * pR = pHost->mpMap->mpRoomDB->getRoom(id);
>         if( pR )
>         {
>             pR->name = name.c_str();
>             pHost->mpMap->setRoomCoordinates( id, x, y, z );
>             pA->addRoom( id );
>             lua_pushnumber( L, id );
>             pA->calcSpan(); // Need to update this for 3D map at least
> if a new z value has been used...
>             pHost->mpMap->mMapGraphNeedsUpdate = true;
>         }
>         else
>         {
>             lua_pushstring( L, "createRoom: failed to create new room" );
>             lua_error( L );
>         }
>     }
>     else
>     {
>         lua_pushstring( L, "createRoom: failed to create new roomID" );
>         lua_error( L );
>     }
>     return 1;
> }
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1226558
>
> Title:
>   getRoom in TArea causes seg fault on map creation
>
> Status in Mudlet the MUD client:
>   New
>
> Bug description:
>   Creating a new map with this code on the latest development branch
>   causes this backtrace:
>
>   0     TArea::fast_ausgaengeBestimmen  TArea.cpp       168     0x5128bb
>   1     TMap::setExit   TMap.cpp        304     0x5281ca
>   2     TLuaInterpreter::setExit        TLuaInterpreter.cpp     6650
>  0x492075
>   3     ??      C:\mingw32\lib\lua51.dll                0x66d862e0
>   4     ??      C:\mingw32\lib\lua51.dll                0x66d8ffa6
>   5     ??      C:\mingw32\lib\lua51.dll                0x66d866e0
>   6     ??      C:\mingw32\lib\lua51.dll                0x66d81590
>   7     ??      C:\mingw32\lib\lua51.dll                0x66d85ad6
>   8     ??      C:\mingw32\lib\lua51.dll                0x66d86843
>   9     ??      C:\mingw32\lib\lua51.dll                0x66d82870
>   10    TLuaInterpreter::compile        TLuaInterpreter.cpp     9649
>  0x49ce7a
>   11    TScript::compileScript  TScript.cpp     150     0x4b04d7
>   12    TScript::setScript      TScript.cpp     143     0x4b048e
>   13    dlgTriggerEditor::saveScript    dlgTriggerEditor.cpp    4282
>  0x456ad9
>   14    dlgTriggerEditor::slot_saveScriptAfterEdit
>  dlgTriggerEditor.cpp    4178    0x456799
>   15    dlgTriggerEditor::slot_save_edit        dlgTriggerEditor.cpp
>  6932    0x46a642
>   16    dlgTriggerEditor::qt_static_metacall    moc_dlgTriggerEditor.cpp
>      509     0x57ecd9
>   17    QMetaObject::activate   qobject.cpp     3479    0x4c94cd0
>   18    QMetaObject::activate   qobject.cpp     3354    0x4c94672
>   19    QAction::triggered      moc_qaction.cpp 356     0x11674669
>   20    QAction::activate       qaction.cpp     1175    0x11673c1e
>   ...   <More>
>
>
>   code:
>
>   -------------------------------------------------
>   --         Put your Lua functions here.        --
>   --                                             --
>   -- Note that you can also use external Scripts --
>   -------------------------------------------------
>   function makeMap()
>   id = 0
>   for i=0,100 do
>         for j=0, 100 do
>                 addRoom(id)
>                 --setRoomArea(id,0) --uncomment this and remove below call
> to avoid seg faults
>                 setRoomName(id, tostring(id))
>                 setRoomCoordinates(id, i, j, 0)
>                 setExit(id-1,id,1)
>                 setExit(id,id-1,2)
>                 setRoomArea(id,0)
>                 id = id+1
>         end
>   end
>   end
>
>   function makeLabels()
>         id=1
>         for i=0,100 do
>                 for j=0, 100 do
>                         --display(id)
>                         x,y,z = getRoomCoordinates(id)
>                         createMapLabel(0,tostring(id),x,y,z,0,255,0,0,0,0)
>                         id = id+1
>                 end
>         end
>   end
>
>   --makeMap()
>   --makeLabels()
>   centerview(1)
>
>   uncomment makeMap and it crashes. It fails when id is 1 as well, so it
>   isn't because of the i-1 setExit bit. It's caused by mpRoomDB not
>   being initialized because there is no area created. Even post
>   creation, the room needs to be assigned to an area first before any
>   calls to mpRoomDB are called, else it will seg fault. It seems like we
>   need some 'void' area that has no name and is just an abyss for rooms
>   waiting to be allocated to avoid breaking scripts.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/mudlet/+bug/1226558/+subscriptions
>

-- 
You received this bug notification because you are a member of Mudlet
Makers, which is subscribed to Mudlet.
https://bugs.launchpad.net/bugs/1226558

Title:
  getRoom in TArea causes seg fault on map creation

Status in Mudlet the MUD client:
  New

Bug description:
  Creating a new map with this code on the latest development branch
  causes this backtrace:

  0	TArea::fast_ausgaengeBestimmen	TArea.cpp	168	0x5128bb	
  1	TMap::setExit	TMap.cpp	304	0x5281ca	
  2	TLuaInterpreter::setExit	TLuaInterpreter.cpp	6650	0x492075	
  3	??	C:\mingw32\lib\lua51.dll		0x66d862e0	
  4	??	C:\mingw32\lib\lua51.dll		0x66d8ffa6	
  5	??	C:\mingw32\lib\lua51.dll		0x66d866e0	
  6	??	C:\mingw32\lib\lua51.dll		0x66d81590	
  7	??	C:\mingw32\lib\lua51.dll		0x66d85ad6	
  8	??	C:\mingw32\lib\lua51.dll		0x66d86843	
  9	??	C:\mingw32\lib\lua51.dll		0x66d82870	
  10	TLuaInterpreter::compile	TLuaInterpreter.cpp	9649	0x49ce7a	
  11	TScript::compileScript	TScript.cpp	150	0x4b04d7	
  12	TScript::setScript	TScript.cpp	143	0x4b048e	
  13	dlgTriggerEditor::saveScript	dlgTriggerEditor.cpp	4282	0x456ad9	
  14	dlgTriggerEditor::slot_saveScriptAfterEdit	dlgTriggerEditor.cpp	4178	0x456799	
  15	dlgTriggerEditor::slot_save_edit	dlgTriggerEditor.cpp	6932	0x46a642	
  16	dlgTriggerEditor::qt_static_metacall	moc_dlgTriggerEditor.cpp	509	0x57ecd9	
  17	QMetaObject::activate	qobject.cpp	3479	0x4c94cd0	
  18	QMetaObject::activate	qobject.cpp	3354	0x4c94672	
  19	QAction::triggered	moc_qaction.cpp	356	0x11674669	
  20	QAction::activate	qaction.cpp	1175	0x11673c1e	
  ...	<More>				

  
  code:

  -------------------------------------------------
  --         Put your Lua functions here.        --
  --                                             --
  -- Note that you can also use external Scripts --
  -------------------------------------------------
  function makeMap()
  id = 0
  for i=0,100 do
  	for j=0, 100 do
  		addRoom(id)
  		--setRoomArea(id,0) --uncomment this and remove below call to avoid seg faults
  		setRoomName(id, tostring(id))
  		setRoomCoordinates(id, i, j, 0)
  		setExit(id-1,id,1)
  		setExit(id,id-1,2)
  		setRoomArea(id,0)
  		id = id+1	
  	end
  end
  end

  function makeLabels()
  	id=1
  	for i=0,100 do
  		for j=0, 100 do
  			--display(id)
  			x,y,z = getRoomCoordinates(id)
  			createMapLabel(0,tostring(id),x,y,z,0,255,0,0,0,0) 
  			id = id+1
  		end
  	end
  end

  --makeMap()
  --makeLabels()
  centerview(1)

  uncomment makeMap and it crashes. It fails when id is 1 as well, so it
  isn't because of the i-1 setExit bit. It's caused by mpRoomDB not
  being initialized because there is no area created. Even post
  creation, the room needs to be assigned to an area first before any
  calls to mpRoomDB are called, else it will seg fault. It seems like we
  need some 'void' area that has no name and is just an abyss for rooms
  waiting to be allocated to avoid breaking scripts.

To manage notifications about this bug go to:
https://bugs.launchpad.net/mudlet/+bug/1226558/+subscriptions


Follow ups

References