@@ -92,68 +92,81 @@ MapBlock* Database_LevelDB::loadBlock(v3s16 blockpos)
92
92
v2s16 p2d (blockpos.X , blockpos.Z );
93
93
94
94
std::string datastr;
95
- leveldb::Status s = m_database->Get (leveldb::ReadOptions (), i64tos (getBlockAsInteger (blockpos)), &datastr);
95
+ leveldb::Status s = m_database->Get (leveldb::ReadOptions (),
96
+ i64tos (getBlockAsInteger (blockpos)), &datastr);
97
+ if (datastr.length () == 0 ) {
98
+ errorstream << " Blank block data in database (datastr.length() == 0) ("
99
+ << blockpos.X << " ," << blockpos.Y << " ," << blockpos.Z << " )" << std::endl;
100
+
101
+ if (g_settings->getBool (" ignore_world_load_errors" )) {
102
+ errorstream << " Ignoring block load error. Duck and cover! "
103
+ << " (ignore_world_load_errors)" << std::endl;
104
+ } else {
105
+ throw SerializationError (" Blank block data in database" );
106
+ }
107
+ }
96
108
97
- if (s.ok ()) {
98
- /*
99
- Make sure sector is loaded
100
- */
101
- MapSector *sector = srvmap->createSector (p2d);
109
+ if (s.ok ()) {
110
+ /*
111
+ Make sure sector is loaded
112
+ */
113
+ MapSector *sector = srvmap->createSector (p2d);
102
114
103
115
try {
104
- std::istringstream is (datastr, std::ios_base::binary);
105
- u8 version = SER_FMT_VER_INVALID;
106
- is.read ((char *)&version, 1 );
107
-
108
- if (is.fail ())
109
- throw SerializationError (" ServerMap::loadBlock(): Failed"
110
- " to read MapBlock version" );
111
-
112
- MapBlock *block = NULL ;
113
- bool created_new = false ;
114
- block = sector->getBlockNoCreateNoEx (blockpos.Y );
115
- if (block == NULL )
116
- {
117
- block = sector->createBlankBlockNoInsert (blockpos.Y );
118
- created_new = true ;
119
- }
120
- // Read basic data
121
- block->deSerialize (is, version, true );
122
- // If it's a new block, insert it to the map
123
- if (created_new)
124
- sector->insertBlock (block);
125
- /*
126
- Save blocks loaded in old format in new format
127
- */
128
-
129
- // if(version < SER_FMT_VER_HIGHEST || save_after_load)
130
- // Only save if asked to; no need to update version
131
- // if(save_after_load)
132
- // saveBlock(block);
133
- // We just loaded it from, so it's up-to-date.
134
- block->resetModified ();
135
-
136
- }
137
- catch (SerializationError &e)
138
- {
139
- errorstream<<" Invalid block data in database"
140
- <<" (" <<blockpos.X <<" ," <<blockpos.Y <<" ," <<blockpos.Z <<" )"
141
- <<" (SerializationError): " <<e.what ()<<std::endl;
142
- // TODO: Block should be marked as invalid in memory so that it is
143
- // not touched but the game can run
144
-
145
- if (g_settings->getBool (" ignore_world_load_errors" )){
146
- errorstream<<" Ignoring block load error. Duck and cover! "
147
- <<" (ignore_world_load_errors)" <<std::endl;
148
- } else {
149
- throw SerializationError (" Invalid block data in database" );
150
- // assert(0);
151
- }
152
- }
153
-
154
- return srvmap->getBlockNoCreateNoEx (blockpos); // should not be using this here
155
- }
156
- return (NULL );
116
+ std::istringstream is (datastr, std::ios_base::binary);
117
+ u8 version = SER_FMT_VER_INVALID;
118
+ is.read ((char *)&version, 1 );
119
+
120
+ if (is.fail ())
121
+ throw SerializationError (" ServerMap::loadBlock(): Failed"
122
+ " to read MapBlock version" );
123
+
124
+ MapBlock *block = NULL ;
125
+ bool created_new = false ;
126
+ block = sector->getBlockNoCreateNoEx (blockpos.Y );
127
+ if (block == NULL )
128
+ {
129
+ block = sector->createBlankBlockNoInsert (blockpos.Y );
130
+ created_new = true ;
131
+ }
132
+
133
+ // Read basic data
134
+ block->deSerialize (is, version, true );
135
+
136
+ // If it's a new block, insert it to the map
137
+ if (created_new)
138
+ sector->insertBlock (block);
139
+
140
+ /*
141
+ Save blocks loaded in old format in new format
142
+ */
143
+ // if(version < SER_FMT_VER_HIGHEST || save_after_load)
144
+ // Only save if asked to; no need to update version
145
+ // if(save_after_load)
146
+ // saveBlock(block);
147
+ // We just loaded it from, so it's up-to-date.
148
+ block->resetModified ();
149
+ }
150
+ catch (SerializationError &e)
151
+ {
152
+ errorstream << " Invalid block data in database"
153
+ << " (" << blockpos.X << " ," << blockpos.Y << " ," << blockpos.Z
154
+ << " ) (SerializationError): " << e.what () << std::endl;
155
+ // TODO: Block should be marked as invalid in memory so that it is
156
+ // not touched but the game can run
157
+
158
+ if (g_settings->getBool (" ignore_world_load_errors" )) {
159
+ errorstream << " Ignoring block load error. Duck and cover! "
160
+ << " (ignore_world_load_errors)" << std::endl;
161
+ } else {
162
+ throw SerializationError (" Invalid block data in database" );
163
+ // assert(0);
164
+ }
165
+ }
166
+
167
+ return srvmap->getBlockNoCreateNoEx (blockpos); // should not be using this here
168
+ }
169
+ return NULL ;
157
170
}
158
171
159
172
void Database_LevelDB::listAllLoadableBlocks (std::list<v3s16> &dst)
0 commit comments