[1.1.88]Changing map gen settings with on_chunk_generated event results in crash

This subforum contains all the issues which we already resolved.
Post Reply
Atraps003
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Thu Jan 04, 2018 6:34 am
Contact:

[1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Atraps003 »

Code: Select all

local count = 0
	local on_chunk_generated = function(event)
	count = count + 1
	if (count == 1681) then
	local surface = game.surfaces[1]
	local iron = "iron-ore"
	local copper = "copper-ore"
	local coal = "coal"
	local stone = "stone"
	local oil = "crude-oil"
	local uranium = "uranium-ore"
	local enemy = "enemy-base"
	local mgs = surface.map_gen_settings
	mgs.autoplace_controls[iron].size = "3"
	mgs.autoplace_controls[iron].frequency = "0.1"
	mgs.autoplace_controls[iron].richness = "0.2"
	mgs.autoplace_controls[copper].size = "3"
	mgs.autoplace_controls[copper].frequency = "0.1"
	mgs.autoplace_controls[copper].richness = "0.2"
	mgs.autoplace_controls[coal].size = "3"
	mgs.autoplace_controls[coal].frequency = "0.1"
	mgs.autoplace_controls[coal].richness = "0.2"
	mgs.autoplace_controls[stone].size = "3"
	mgs.autoplace_controls[stone].frequency = "0.1"
	mgs.autoplace_controls[stone].richness = "0.2"
	mgs.autoplace_controls[oil].size = "10"
	mgs.autoplace_controls[oil].frequency = "0.1"
	mgs.autoplace_controls[oil].richness = "0.03"
	mgs.autoplace_controls[uranium].size = "3"
	mgs.autoplace_controls[uranium].frequency = "0.1"
	mgs.autoplace_controls[uranium].richness = "0.2"
	mgs.autoplace_controls[enemy].size = "10"
	mgs.autoplace_controls[enemy].frequency = "0.1"
	surface.map_gen_settings = mgs
	end
end

Factorio crashed. Generating symbolized stacktrace, please wait ...
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\surface\surface.cpp (1687): Surface::changeMapGenSettings
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luasurface.cpp (2395): LuaSurface::luaWriteMapGenSettings
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luasurface.cpp (643): LuaSurface::luaNewIndex
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luabinder.hpp (348): LuaBinder<LuaRandomGenerator>::callWrapperOnObject
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\ldo.c (350): luaD_precall
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\ldo.c (423): luaD_call
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\lvm.c (104): callTM
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\lvm.c (168): luaV_settable
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\lvm.c (604): luaV_execute
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\lapi.c (1067): f_call
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\ldo.c (137): luaD_rawrunprotected
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\ldo.c (623): luaD_pcall
c:\users\build\appdata\local\temp\factorio-build-pexkpd\libraries\lua\lapi.c (1093): lua_pcallk
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\util\luahelper.cpp (4407): LuaHelper::pCallWithStackTrace
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luagamescript.cpp (1119): LuaGameScript::runEventHandler
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luaeventdispatcher.cpp (687): LuaEventDispatcher::run
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\script\luaeventdispatcher.cpp (513): LuaEventDispatcher::dispatch
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\map\entitymapgenerationtask.cpp (279): EntityMapGenerationTask::apply
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\map\mapgenerationhelper.cpp (92): MapGenerationHelper::applyTaskResult
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\map\mapgenerationmanager.cpp (265): MapGenerationManager::update
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\surface\surface.cpp (1615): Surface::update
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\map\map.cpp (1630): Map::updateEntities
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\game.cpp (210): Game::update
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\scenario\scenario.cpp (1348): Scenario::update
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\scenario\scenario.cpp (1237): Scenario::updateStep
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\mainloop.cpp (1350): MainLoop::gameUpdateStep
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\mainloop.cpp (1203): MainLoop::gameUpdateLoop
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\functional (15732480): std::_Func_impl_no_alloc<<lambda_df7262221d3c1f1d60586a46e6ec37ec>,void>::_Do_call
c:\users\build\appdata\local\temp\factorio-build-pexkpd\src\util\workerthread.cpp (73): WorkerThread::loop
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (230): std::_LaunchPad<std::unique_ptr<std::tuple<void (__cdecl SoundLibrary::AsyncLoader::*)(void),SoundLibrary::AsyncLoader *>,std::default_delete<std::tuple<void (__cdecl SoundLibrary::AsyncLoader::*)(void),SoundLibrary::AsyncLoader *> > > >::_Go
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (209): std::_Pad::_Call_func
minkernel\crts\ucrt\src\appcrt\startup\thread.cpp (97): thread_start<unsigned int (__cdecl*)(void *),1>
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 0000000076DD59CD)
0000000076DD59CD (kernel32): (filename not available): BaseThreadInitThunk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 000000007700B981)
000000007700B981 (ntdll): (filename not available): RtlUserThreadStart
Stack trace logging done
67.040 Error MapGenerationManager.cpp:256: MapGenerationHelper::applyTaskResult(..., force) didn't finish all requests.
67.040 Error CrashHandler.cpp:641: Received 22
Logger::writeStacktrace skipped.
67.040 Error CrashHandler.cpp:195: Map tick at moment of crash: 2486
67.091 Info CrashHandler.cpp:315: Executable CRC: 2419858143
Attachments
crash-on_chunk_generated.zip
(4.08 MiB) Downloaded 42 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Rseding91 »

Thanks for the report. Because of how map generation works in order to change map gen settings all existing chunks partially generated have to be finished. That means that changing map gen settings during the chunk generated event is not possible and so the game detects it is happening and aborts.

Mods are not allowed to change map gen settings during the chunk generated event.
If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Rseding91 »

I’m open to a better error message if someone can think of one.
If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Rseding91 »

I’ve been thinking about this more (because… well as a programmer I like challenges) and I think I could make this work. The question is; how would you as a mod author expect it to work?

If you change the map gen settings in the event would you expect all future events to be using the new settings or would you expect future events to eventually use the new settings?
If you want to get ahold of me I'm almost always on Discord.

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Silari »

I feel like having the chunks that are partially generated to finish using the old settings then using the new settings on everything made after that would be expected if it's not possible to have those settings affect the current chunk(s) generating.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Rseding91 »

Ok, I spent some time today and re-worked map generation to allow this for the next release.
If you want to get ahold of me I'm almost always on Discord.

Atraps003
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Thu Jan 04, 2018 6:34 am
Contact:

Re: [1.1.88]Changing map gen settings with on_chunk_generated event results in crash

Post by Atraps003 »

Thanks! Partially generated chunks finishing with old settings works for me.

Post Reply

Return to “Resolved Problems and Bugs”